Skip to content

Commit a2afd32

Browse files
committed
add more listeners to handler
1 parent c9cdb9e commit a2afd32

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument
5+
6+
import com.intellij.codeInsight.editorActions.EnterHandler
7+
import com.intellij.openapi.actionSystem.DataContext
8+
import com.intellij.openapi.editor.Caret
9+
import com.intellij.openapi.editor.Editor
10+
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
11+
12+
class AmazonQLspEnterHandler(
13+
private val originalHandler: EditorActionHandler,
14+
private val textDocumentHandler: TextDocumentServiceHandler,
15+
) : EnterHandler(originalHandler) {
16+
override fun executeWriteAction(editor: Editor, caret: Caret?, dataContext: DataContext?) {
17+
originalHandler.execute(editor, caret, dataContext)
18+
textDocumentHandler.handleInlineCompletion(editor)
19+
}
20+
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument
55

6+
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate
67
import com.intellij.codeInsight.lookup.Lookup
78
import com.intellij.codeInsight.lookup.LookupEvent
89
import com.intellij.codeInsight.lookup.LookupListener
910
import com.intellij.codeInsight.lookup.LookupManagerListener
1011
import com.intellij.codeInsight.lookup.impl.LookupImpl
1112
import com.intellij.openapi.Disposable
13+
import com.intellij.openapi.actionSystem.IdeActions
1214
import com.intellij.openapi.editor.Document
1315
import com.intellij.openapi.editor.Editor
16+
import com.intellij.openapi.editor.actionSystem.EditorActionManager
1417
import com.intellij.openapi.fileEditor.FileDocumentManager
1518
import com.intellij.openapi.fileEditor.FileDocumentManagerListener
1619
import com.intellij.openapi.fileEditor.FileEditorManager
@@ -21,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFileManager
2124
import com.intellij.openapi.vfs.newvfs.BulkFileListener
2225
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
2326
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
27+
import com.intellij.psi.PsiFile
2428
import org.eclipse.lsp4j.DidChangeTextDocumentParams
2529
import org.eclipse.lsp4j.DidCloseTextDocumentParams
2630
import 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

Comments
 (0)