@@ -55,6 +55,7 @@ import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
5555import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
5656import software.aws.toolkits.jetbrains.core.credentials.pinning.CodeWhispererConnection
5757import software.aws.toolkits.jetbrains.services.amazonq.SUPPLEMENTAL_CONTEXT_TIMEOUT
58+ import com.intellij.openapi.application.ReadAction
5859import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
5960import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.textDocument.InlineCompletionContext
6061import 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