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 2 commits
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 @@ -39,6 +39,7 @@ import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.isDeveloperMode
import software.aws.toolkits.jetbrains.services.amazonq.lsp.encryption.JwtEncryptionManager
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.createExtendedClientMetadata
import software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument.TextDocumentServiceHandler
import software.aws.toolkits.jetbrains.services.telemetry.ClientMetadata
import java.io.IOException
import java.io.OutputStreamWriter
Expand Down Expand Up @@ -235,6 +236,12 @@ private class AmazonQServerInstance(private val project: Project, private val cs
}
languageServer.initialized(InitializedParams())
}

TextDocumentServiceHandler(
project,
languageServer,
this
)
}

override fun dispose() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument

import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.vfs.VirtualFile
import org.eclipse.lsp4j.DidCloseTextDocumentParams
import org.eclipse.lsp4j.DidOpenTextDocumentParams
import org.eclipse.lsp4j.TextDocumentIdentifier
import org.eclipse.lsp4j.TextDocumentItem
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLanguageServer

class TextDocumentServiceHandler(
private val project: Project,
private val languageServer: AmazonQLanguageServer,
private val serverInstance: Disposable
) {

init {
subscribeToFileEditorEvents()
}

// for textDocument/ didOpen and didClose
private fun subscribeToFileEditorEvents() {
project.messageBus.connect(serverInstance).subscribe(
FileEditorManagerListener.FILE_EDITOR_MANAGER,
object: FileEditorManagerListener {
override fun fileOpened(
source: FileEditorManager,
file: VirtualFile
) {
languageServer.textDocumentService.didOpen(
DidOpenTextDocumentParams().apply {
textDocument = TextDocumentItem().apply {
uri = file.url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url/uri logic should be consistent across all messages

text = file.inputStream.readAllBytes().decodeToString()
}
}
)
}

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

private fun didChange() {

Check warning on line 62 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 66 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