Skip to content

Commit 12a5484

Browse files
committed
make class the listener
1 parent 334feda commit 12a5484

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,41 @@ class TextDocumentServiceHandler(
1818
private val project: Project,
1919
private val languageServer: AmazonQLanguageServer,
2020
private val serverInstance: Disposable
21-
) {
21+
) : FileEditorManagerListener {
2222

2323
init {
2424
subscribeToFileEditorEvents()
2525
}
2626

27-
// for textDocument/ didOpen and didClose
2827
private fun subscribeToFileEditorEvents() {
2928
project.messageBus.connect(serverInstance).subscribe(
3029
FileEditorManagerListener.FILE_EDITOR_MANAGER,
31-
object: FileEditorManagerListener {
32-
override fun fileOpened(
33-
source: FileEditorManager,
34-
file: VirtualFile
35-
) {
36-
languageServer.textDocumentService.didOpen(
37-
DidOpenTextDocumentParams().apply {
38-
textDocument = TextDocumentItem().apply {
39-
uri = file.url
40-
text = file.inputStream.readAllBytes().decodeToString()
41-
}
42-
}
43-
)
30+
this
31+
)
32+
}
33+
34+
override fun fileOpened(
35+
source: FileEditorManager,
36+
file: VirtualFile
37+
) {
38+
languageServer.textDocumentService.didOpen(
39+
DidOpenTextDocumentParams().apply {
40+
textDocument = TextDocumentItem().apply {
41+
uri = file.url
42+
text = file.inputStream.readAllBytes().decodeToString()
4443
}
44+
}
45+
)
46+
}
4547

46-
override fun fileClosed(
47-
source: FileEditorManager,
48-
file: VirtualFile
49-
) {
50-
languageServer.textDocumentService.didClose(
51-
DidCloseTextDocumentParams().apply {
52-
textDocument = TextDocumentIdentifier().apply {
53-
uri = file.url
54-
}
55-
}
56-
)
48+
override fun fileClosed(
49+
source: FileEditorManager,
50+
file: VirtualFile
51+
) {
52+
languageServer.textDocumentService.didClose(
53+
DidCloseTextDocumentParams().apply {
54+
textDocument = TextDocumentIdentifier().apply {
55+
uri = file.url
5756
}
5857
}
5958
)

0 commit comments

Comments
 (0)