Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amazonq): implement TextDocumentService message handler #5380

Open
wants to merge 25 commits into
base: feature/q-lsp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4da2951
init
samgst-amazon Feb 14, 2025
334feda
implement file open and close
samgst-amazon Feb 14, 2025
12a5484
make class the listener
samgst-amazon Feb 15, 2025
878b06e
detekt
samgst-amazon Feb 15, 2025
79b1f38
init executeIfRunning implementation
samgst-amazon Feb 17, 2025
19478d9
detekt
samgst-amazon Feb 17, 2025
9794098
remove unused param
samgst-amazon Feb 17, 2025
41c225b
didChange impl
samgst-amazon Feb 17, 2025
6cda596
didSave impl
samgst-amazon Feb 17, 2025
1f2de8b
constructor param
samgst-amazon Feb 17, 2025
cac22b9
executeIfRunning whole function
samgst-amazon Feb 17, 2025
bd0bd10
move executeIfRunning
samgst-amazon Feb 18, 2025
8961b5d
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 18, 2025
1de97ce
use companion obj call
samgst-amazon Feb 18, 2025
43774b2
make serverInstance private
samgst-amazon Feb 18, 2025
22071e6
null uri handling
samgst-amazon Feb 19, 2025
b6af245
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 19, 2025
482a6ff
add testing for TextDocumentServiceHandler
samgst-amazon Feb 24, 2025
e4a9b9e
additional tests
samgst-amazon Feb 24, 2025
0d26dfe
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 24, 2025
83f7d12
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 26, 2025
a026102
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 28, 2025
c842495
fix test
samgst-amazon Feb 28, 2025
370ecc5
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon Feb 28, 2025
b69d6c6
detekt
samgst-amazon Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal class LSPProcessListener : ProcessListener {

@Service(Service.Level.PROJECT)
class AmazonQLspService(private val project: Project, private val cs: CoroutineScope) : Disposable {
private var instance: AmazonQServerInstance? = null
internal var instance: AmazonQServerInstance? = null

init {
cs.launch {
Expand All @@ -112,12 +112,12 @@ class AmazonQLspService(private val project: Project, private val cs: CoroutineS
}
}

private class AmazonQServerInstance(private val project: Project, private val cs: CoroutineScope) : Disposable {
internal class AmazonQServerInstance(private val project: Project, private val cs: CoroutineScope) : Disposable {
private val encryptionManager = JwtEncryptionManager()

private val launcher: Launcher<AmazonQLanguageServer>

private val languageServer: AmazonQLanguageServer
internal val languageServer: AmazonQLanguageServer
get() = launcher.remoteProxy

@Suppress("ForbiddenVoid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import org.eclipse.lsp4j.TextDocumentIdentifier
import org.eclipse.lsp4j.TextDocumentItem
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLanguageServer
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService

class TextDocumentServiceHandler(
private val project: Project,
private val languageServer: AmazonQLanguageServer,

Check warning on line 20 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "languageServer" is never used
private val serverInstance: Disposable,
) : FileEditorManagerListener {

Expand All @@ -31,36 +32,43 @@
)
}

fun executeIfRunning(project: Project, runnable: (AmazonQLanguageServer) -> Unit) =

Check notice on line 35 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'executeIfRunning' could be private
AmazonQLspService.getInstance(project).instance?.languageServer?.let { runnable(it)}

override fun fileOpened(
source: FileEditorManager,
file: VirtualFile,
file: VirtualFile
) {
languageServer.textDocumentService.didOpen(
DidOpenTextDocumentParams().apply {
textDocument = TextDocumentItem().apply {
uri = file.url
text = file.inputStream.readAllBytes().decodeToString()
executeIfRunning(project) {
it.textDocumentService.didOpen(
DidOpenTextDocumentParams().apply {
textDocument = TextDocumentItem().apply {
uri = file.url
text = file.inputStream.readAllBytes().decodeToString()
}
}
}
)
)
}
}

override fun fileClosed(
source: FileEditorManager,
file: VirtualFile,
) {
languageServer.textDocumentService.didClose(
DidCloseTextDocumentParams().apply {
textDocument = TextDocumentIdentifier().apply {
uri = file.url
executeIfRunning(project) {
it.textDocumentService.didClose(
DidCloseTextDocumentParams().apply {
textDocument = TextDocumentIdentifier().apply {
uri = file.url
}
}
}
)
)
}
}

private fun didChange() {

Check warning on line 69 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "didChange" is never used
}

private fun didSave() {

Check warning on line 72 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "didSave" is never used
}
}
Loading