-
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
Changes from 5 commits
4da2951
334feda
12a5484
878b06e
79b1f38
19478d9
9794098
41c225b
6cda596
1f2de8b
cac22b9
bd0bd10
8961b5d
1de97ce
43774b2
22071e6
b6af245
482a6ff
e4a9b9e
0d26dfe
83f7d12
a026102
c842495
370ecc5
b69d6c6
175b13a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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.fileEditor.FileEditorManager | ||
import com.intellij.openapi.fileEditor.FileEditorManagerListener | ||
import com.intellij.openapi.project.Project | ||
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 | ||
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
|
||
|
||
private val serverInstance: Disposable, | ||
|
||
) : FileEditorManagerListener { | ||
|
||
init { | ||
subscribeToFileEditorEvents() | ||
} | ||
|
||
private fun subscribeToFileEditorEvents() { | ||
project.messageBus.connect(serverInstance).subscribe( | ||
FileEditorManagerListener.FILE_EDITOR_MANAGER, | ||
this | ||
) | ||
} | ||
|
||
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
|
||
|
||
AmazonQLspService.getInstance(project).instance?.languageServer?.let { runnable(it)} | ||
|
||
override fun fileOpened( | ||
source: FileEditorManager, | ||
file: VirtualFile | ||
) { | ||
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, | ||
) { | ||
executeIfRunning(project) { | ||
it.textDocumentService.didClose( | ||
DidCloseTextDocumentParams().apply { | ||
textDocument = TextDocumentIdentifier().apply { | ||
uri = file.url | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun didChange() { | ||
|
||
} | ||
|
||
private fun didSave() { | ||
|
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.