Skip to content

Commit 5608b8f

Browse files
authored
fix(amazonq): fix merge issue in QInlineCompletionProvider (#5886)
1 parent 6ab2a90 commit 5608b8f

File tree

1 file changed

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

1 file changed

+11
-14
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/QInlineCompletionProvider.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ import kotlinx.coroutines.withContext
4646
import migration.software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
4747
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
4848
import org.eclipse.lsp4j.jsonrpc.messages.Either
49-
import software.amazon.awssdk.services.ssooidc.model.InvalidGrantException
5049
import software.aws.toolkits.core.utils.debug
5150
import software.aws.toolkits.core.utils.getLogger
51+
import software.aws.toolkits.core.utils.warn
5252
import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
5353
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
5454
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
@@ -601,20 +601,17 @@ class QInlineCompletionProvider(private val cs: CoroutineScope) : InlineCompleti
601601
// https://github.com/aws/language-servers/blob/1f3e93024eeb22186a34f0bd560f8d552f517300/server/aws-lsp-codewhisperer/src/language-server/chat/utils.ts#L22-L23
602602
// error data is nullable
603603
if (e.responseError.data?.toString()?.contains("E_AMAZON_Q_CONNECTION_EXPIRED") == true) {
604-
// kill the session if the connection is expired
605-
val connection = ToolkitConnectionManager
606-
.getInstance(project)
607-
.activeConnectionForFeature(QConnection.getInstance()) as? AwsBearerTokenConnection
608-
val tokenProvider = connection?.let { it.getConnectionSettings().tokenProvider.delegate as? BearerTokenProvider }
609-
tokenProvider?.let {
610-
// TODO: fragile
611-
try {
612-
it.refresh()
613-
} catch (_: InvalidGrantException) {
614-
it.invalidate()
615-
CodeWhispererUtil.reconnectCodeWhisperer(project)
616-
}
604+
try {
605+
// kill the session if the connection is expired
606+
val connection = ToolkitConnectionManager
607+
.getInstance(project)
608+
.activeConnectionForFeature(QConnection.getInstance()) as? AwsBearerTokenConnection
609+
connection?.let { it.getConnectionSettings().tokenProvider.delegate as? BearerTokenProvider }
610+
?.invalidate()
611+
} catch (e: Exception) {
612+
LOG.warn(e) { "Failed to invalidate existing token in response to E_AMAZON_Q_CONNECTION_EXPIRED" }
617613
}
614+
CodeWhispererUtil.reconnectCodeWhisperer(project)
618615
}
619616
}
620617
return null

0 commit comments

Comments
 (0)