33
44package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument
55
6+ import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
67import com.intellij.codeInsight.lookup.Lookup
78import com.intellij.codeInsight.lookup.LookupEvent
89import com.intellij.codeInsight.lookup.LookupListener
910import com.intellij.codeInsight.lookup.LookupManagerListener
1011import com.intellij.codeInsight.lookup.impl.LookupImpl
1112import com.intellij.openapi.Disposable
13+ import com.intellij.openapi.actionSystem.IdeActions
1214import com.intellij.openapi.editor.Document
1315import com.intellij.openapi.editor.Editor
16+ import com.intellij.openapi.editor.actionSystem.EditorActionManager
1417import com.intellij.openapi.fileEditor.FileDocumentManager
1518import com.intellij.openapi.fileEditor.FileDocumentManagerListener
1619import com.intellij.openapi.fileEditor.FileEditorManager
@@ -21,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFileManager
2124import com.intellij.openapi.vfs.newvfs.BulkFileListener
2225import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
2326import com.intellij.openapi.vfs.newvfs.events.VFileEvent
27+ import com.intellij.psi.PsiFile
2428import org.eclipse.lsp4j.DidChangeTextDocumentParams
2529import org.eclipse.lsp4j.DidCloseTextDocumentParams
2630import org.eclipse.lsp4j.DidOpenTextDocumentParams
@@ -43,7 +47,8 @@ class TextDocumentServiceHandler(
4347) : FileDocumentManagerListener,
4448 FileEditorManagerListener ,
4549 BulkFileListener ,
46- LookupManagerListener {
50+ LookupManagerListener ,
51+ TypedHandlerDelegate () {
4752
4853 init {
4954 // didOpen & didClose events
@@ -70,6 +75,13 @@ class TextDocumentServiceHandler(
7075 this
7176 )
7277
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+
7385 // open files on startup
7486 val fileEditorManager = FileEditorManager .getInstance(project)
7587 fileEditorManager.openFiles.forEach { file ->
@@ -117,7 +129,12 @@ class TextDocumentServiceHandler(
117129 })
118130 }
119131
120- private fun handleInlineCompletion (editor : Editor ) {
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 ) {
121138 AmazonQLspService .executeIfRunning(project) { server ->
122139 val params = buildInlineCompletionParams(editor)
123140 server.inlineCompletionWithReferences(params)
0 commit comments