-
Notifications
You must be signed in to change notification settings - Fork 251
feat(amazonq): implement TextDocumentService message handler #5380
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4da2951
init
samgst-amazon 334feda
implement file open and close
samgst-amazon 12a5484
make class the listener
samgst-amazon 878b06e
detekt
samgst-amazon 79b1f38
init executeIfRunning implementation
samgst-amazon 19478d9
detekt
samgst-amazon 9794098
remove unused param
samgst-amazon 41c225b
didChange impl
samgst-amazon 6cda596
didSave impl
samgst-amazon 1f2de8b
constructor param
samgst-amazon cac22b9
executeIfRunning whole function
samgst-amazon bd0bd10
move executeIfRunning
samgst-amazon 8961b5d
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon 1de97ce
use companion obj call
samgst-amazon 43774b2
make serverInstance private
samgst-amazon 22071e6
null uri handling
samgst-amazon b6af245
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon 482a6ff
add testing for TextDocumentServiceHandler
samgst-amazon e4a9b9e
additional tests
samgst-amazon 0d26dfe
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon 83f7d12
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon a026102
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon c842495
fix test
samgst-amazon 370ecc5
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon b69d6c6
detekt
samgst-amazon 175b13a
Merge branch 'feature/q-lsp' into samgst/q-lsp-TDmessages
samgst-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...re/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
samgst-amazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
samgst-amazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
||
|
||
} | ||
|
||
private fun didSave() { | ||
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.