Skip to content

Commit 72d1c1f

Browse files
committed
triggerType passed through
1 parent e60ee13 commit 72d1c1f

File tree

1 file changed

+22
-14
lines changed
  • plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service

1 file changed

+22
-14
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
5555
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
5656
import software.aws.toolkits.jetbrains.core.credentials.pinning.CodeWhispererConnection
5757
import software.aws.toolkits.jetbrains.services.amazonq.SUPPLEMENTAL_CONTEXT_TIMEOUT
58+
import com.intellij.openapi.application.ReadAction
5859
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
5960
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionContext
6061
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionTriggerKind
@@ -212,7 +213,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
212213
return
213214
}
214215

215-
handleInlineCompletion(editor)
216+
handleInlineCompletion(editor, triggerTypeInfo)
216217
invokeCodeWhispererInBackground(requestContext)
217218
}
218219

@@ -535,10 +536,10 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
535536
return nextStates
536537
}
537538

538-
internal fun handleInlineCompletion(editor: Editor) {
539+
private fun handleInlineCompletion(editor: Editor, triggerType: TriggerTypeInfo) {
539540
editor.project?.let { project ->
540541
AmazonQLspService.executeIfRunning(project) { server ->
541-
val params = buildInlineCompletionParams(editor)
542+
val params = createInlineCompletionParams(editor, triggerType)
542543
server.inlineCompletionWithReferences(params)
543544
}
544545
}
@@ -723,17 +724,24 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
723724
return states
724725
}
725726

726-
private fun buildInlineCompletionParams(editor: Editor): InlineCompletionWithReferencesParams =
727-
InlineCompletionWithReferencesParams(
728-
context = InlineCompletionContext(
729-
triggerKind = InlineCompletionTriggerKind.Invoke
730-
)
731-
).apply {
732-
textDocument = TextDocumentIdentifier(toUriString(editor.virtualFile))
733-
position = Position(
734-
editor.caretModel.primaryCaret.visualPosition.line,
735-
editor.caretModel.primaryCaret.offset
736-
)
727+
private fun createInlineCompletionParams(editor: Editor, triggerTypeInfo: TriggerTypeInfo): InlineCompletionWithReferencesParams =
728+
ReadAction.compute<InlineCompletionWithReferencesParams, RuntimeException> {
729+
InlineCompletionWithReferencesParams(
730+
context = InlineCompletionContext(
731+
// Map the triggerTypeInfo to appropriate InlineCompletionTriggerKind
732+
triggerKind = when (triggerTypeInfo.triggerType) {
733+
CodewhispererTriggerType.OnDemand -> InlineCompletionTriggerKind.Invoke
734+
CodewhispererTriggerType.AutoTrigger -> InlineCompletionTriggerKind.Automatic
735+
else -> InlineCompletionTriggerKind.Invoke
736+
}
737+
)
738+
).apply {
739+
textDocument = TextDocumentIdentifier(toUriString(editor.virtualFile))
740+
position = Position(
741+
editor.caretModel.primaryCaret.visualPosition.line,
742+
editor.caretModel.primaryCaret.offset
743+
)
744+
}
737745
}
738746

739747
private fun addPopupChildDisposables(popup: JBPopup) {

0 commit comments

Comments
 (0)