@@ -5,34 +5,60 @@ package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument
5
5
6
6
import com.intellij.openapi.Disposable
7
7
import com.intellij.openapi.project.Project
8
- import com.intellij.openapi.vfs.VirtualFileManager
9
- import com.intellij.openapi.vfs.newvfs.BulkFileListener
10
- import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
11
- import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
12
- import com.intellij.openapi.vfs.newvfs.events.VFileEvent
13
- import org.eclipse.lsp4j.CreateFilesParams
14
- import org.eclipse.lsp4j.DeleteFilesParams
15
- import org.eclipse.lsp4j.FileCreate
16
- import org.eclipse.lsp4j.FileDelete
8
+ import com.intellij.openapi.fileEditor.FileEditorManager
9
+ import com.intellij.openapi.fileEditor.FileEditorManagerListener
10
+ import com.intellij.openapi.vfs.VirtualFile
11
+ import org.eclipse.lsp4j.DidCloseTextDocumentParams
12
+ import org.eclipse.lsp4j.DidOpenTextDocumentParams
13
+ import org.eclipse.lsp4j.TextDocumentIdentifier
14
+ import org.eclipse.lsp4j.TextDocumentItem
17
15
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLanguageServer
18
- import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
19
16
20
17
class TextDocumentServiceHandler (
21
18
private val project : Project ,
22
- private val languageServer : AmazonQLanguageServer
23
- ) : Disposable {
24
-
25
- fun startTextDocumentServiceListeners () {
19
+ private val languageServer : AmazonQLanguageServer ,
20
+ private val serverInstance : Disposable
21
+ ) {
26
22
23
+ init {
24
+ subscribeToFileEditorEvents()
27
25
}
28
26
29
- private fun didClose () {
27
+ // for textDocument/ didOpen and didClose
28
+ private fun subscribeToFileEditorEvents () {
29
+ project.messageBus.connect(serverInstance).subscribe(
30
+ 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
+ )
44
+ }
30
45
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
+ )
57
+ }
58
+ }
59
+ )
31
60
}
32
61
33
- private fun didOpen () {
34
-
35
- }
36
62
private fun didChange () {
37
63
38
64
}
@@ -41,6 +67,4 @@ class TextDocumentServiceHandler(
41
67
42
68
}
43
69
44
- override fun dispose () {
45
- }
46
70
}
0 commit comments