Skip to content

Commit 68e82e0

Browse files
committed
fix(amazonq): always send creds on lsp init if available
1 parent ca4e3ce commit 68e82e0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import kotlinx.coroutines.CoroutineScope
2424
import kotlinx.coroutines.Deferred
2525
import kotlinx.coroutines.TimeoutCancellationException
2626
import kotlinx.coroutines.async
27-
import kotlinx.coroutines.launch
27+
import kotlinx.coroutines.future.asCompletableFuture
2828
import kotlinx.coroutines.runBlocking
2929
import kotlinx.coroutines.sync.Mutex
3030
import kotlinx.coroutines.sync.withLock
@@ -316,11 +316,18 @@ private class AmazonQServerInstance(private val project: Project, private val cs
316316
initializeResult
317317
}
318318

319-
DefaultAuthCredentialsService(project, encryptionManager, this)
320-
TextDocumentServiceHandler(project, this)
321-
WorkspaceServiceHandler(project, this)
322-
cs.launch {
323-
DefaultModuleDependenciesService(project, this@AmazonQServerInstance)
319+
// invokeOnCompletion results in weird lock/timeout error
320+
initializeResult.asCompletableFuture().handleAsync { r, ex ->
321+
if (ex != null) {
322+
return@handleAsync
323+
}
324+
325+
this@AmazonQServerInstance.apply {
326+
DefaultAuthCredentialsService(project, encryptionManager, this)
327+
TextDocumentServiceHandler(project, this)
328+
WorkspaceServiceHandler(project, this)
329+
DefaultModuleDependenciesService(project, this)
330+
}
324331
}
325332
}
326333

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/auth/DefaultAuthCredentialsService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DefaultAuthCredentialsService(
2626
BearerTokenProviderListener {
2727
init {
2828
project.messageBus.connect(serverInstance).subscribe(BearerTokenProviderListener.TOPIC, this)
29+
30+
onChange("init", null)
2931
}
3032

3133
override fun onChange(providerId: String, newScopes: List<String>?) {

0 commit comments

Comments
 (0)