33
44package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument
55
6- import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
7- import com.intellij.codeInsight.lookup.Lookup
8- import com.intellij.codeInsight.lookup.LookupEvent
9- import com.intellij.codeInsight.lookup.LookupListener
10- import com.intellij.codeInsight.lookup.LookupManagerListener
11- import com.intellij.codeInsight.lookup.impl.LookupImpl
126import com.intellij.openapi.Disposable
13- import com.intellij.openapi.actionSystem.IdeActions
147import com.intellij.openapi.editor.Document
15- import com.intellij.openapi.editor.Editor
16- import com.intellij.openapi.editor.actionSystem.EditorActionManager
178import com.intellij.openapi.fileEditor.FileDocumentManager
189import com.intellij.openapi.fileEditor.FileDocumentManagerListener
1910import com.intellij.openapi.fileEditor.FileEditorManager
@@ -24,20 +15,15 @@ import com.intellij.openapi.vfs.VirtualFileManager
2415import com.intellij.openapi.vfs.newvfs.BulkFileListener
2516import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
2617import com.intellij.openapi.vfs.newvfs.events.VFileEvent
27- import com.intellij.psi.PsiFile
2818import org.eclipse.lsp4j.DidChangeTextDocumentParams
2919import org.eclipse.lsp4j.DidCloseTextDocumentParams
3020import org.eclipse.lsp4j.DidOpenTextDocumentParams
3121import org.eclipse.lsp4j.DidSaveTextDocumentParams
32- import org.eclipse.lsp4j.Position
3322import org.eclipse.lsp4j.TextDocumentContentChangeEvent
3423import org.eclipse.lsp4j.TextDocumentIdentifier
3524import org.eclipse.lsp4j.TextDocumentItem
3625import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
3726import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
38- import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionContext
39- import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionTriggerKind
40- import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionWithReferencesParams
4127import software.aws.toolkits.jetbrains.services.amazonq.lsp.util.FileUriUtil.toUriString
4228import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
4329
@@ -46,9 +32,7 @@ class TextDocumentServiceHandler(
4632 serverInstance : Disposable ,
4733) : FileDocumentManagerListener,
4834 FileEditorManagerListener ,
49- BulkFileListener ,
50- LookupManagerListener ,
51- TypedHandlerDelegate () {
35+ BulkFileListener {
5236
5337 init {
5438 // didOpen & didClose events
@@ -69,19 +53,6 @@ class TextDocumentServiceHandler(
6953 this
7054 )
7155
72- // aws/textDocument/inlineCompletionWithReferences events
73- project.messageBus.connect(serverInstance).subscribe(
74- LookupManagerListener .TOPIC ,
75- this
76- )
77-
78- val editorActionManager = EditorActionManager .getInstance()
79- val originalHandler = editorActionManager.getActionHandler(IdeActions .ACTION_EDITOR_ENTER )
80- editorActionManager.setActionHandler(
81- IdeActions .ACTION_EDITOR_ENTER ,
82- AmazonQLspEnterHandler (originalHandler, this )
83- )
84-
8556 // open files on startup
8657 val fileEditorManager = FileEditorManager .getInstance(project)
8758 fileEditorManager.openFiles.forEach { file ->
@@ -104,56 +75,6 @@ class TextDocumentServiceHandler(
10475 }
10576 }
10677
107- override fun activeLookupChanged (oldLookup : Lookup ? , newLookup : Lookup ? ) {
108- if (oldLookup != null || newLookup == null ) return
109-
110- newLookup.addLookupListener(object : LookupListener {
111- override fun itemSelected (event : LookupEvent ) {
112- val editor = event.lookup.editor
113- if (! (event.lookup as LookupImpl ).isShown) {
114- cleanup()
115- return
116- }
117-
118- handleInlineCompletion(editor)
119- cleanup()
120- }
121-
122- override fun lookupCanceled (event : LookupEvent ) {
123- cleanup()
124- }
125-
126- private fun cleanup () {
127- newLookup.removeLookupListener(this )
128- }
129- })
130- }
131-
132- override fun charTyped (c : Char , project : Project , editor : Editor , psiFiles : PsiFile ): Result {
133- handleInlineCompletion(editor)
134- return Result .CONTINUE
135- }
136-
137- fun handleInlineCompletion (editor : Editor ) {
138- AmazonQLspService .executeIfRunning(project) { server ->
139- val params = buildInlineCompletionParams(editor)
140- server.inlineCompletionWithReferences(params)
141- }
142- }
143-
144- private fun buildInlineCompletionParams (editor : Editor ): InlineCompletionWithReferencesParams =
145- InlineCompletionWithReferencesParams (
146- context = InlineCompletionContext (
147- triggerKind = InlineCompletionTriggerKind .Invoke
148- )
149- ).apply {
150- textDocument = TextDocumentIdentifier (toUriString(editor.virtualFile))
151- position = Position (
152- editor.caretModel.primaryCaret.visualPosition.line,
153- editor.caretModel.primaryCaret.offset
154- )
155- }
156-
15778 override fun beforeDocumentSaving (document : Document ) {
15879 AmazonQLspService .executeIfRunning(project) { languageServer ->
15980 val file = FileDocumentManager .getInstance().getFile(document) ? : return @executeIfRunning
0 commit comments