Skip to content

Commit 80f8b47

Browse files
committed
coroutines/verbosity
1 parent 5a7c5fe commit 80f8b47

File tree

17 files changed

+254
-229
lines changed

17 files changed

+254
-229
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QRefreshPanelAction.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import com.intellij.icons.AllIcons
77
import com.intellij.openapi.actionSystem.ActionUpdateThread
88
import com.intellij.openapi.actionSystem.AnActionEvent
99
import com.intellij.openapi.application.ApplicationManager
10+
import com.intellij.openapi.progress.currentThreadCoroutineScope
1011
import com.intellij.openapi.project.DumbAwareAction
1112
import com.intellij.util.messages.Topic
13+
import kotlinx.coroutines.launch
1214
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
1315
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.ChatCommunicationManager
1416
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_TAB_REMOVE
@@ -22,9 +24,11 @@ class QRefreshPanelAction : DumbAwareAction(AmazonQBundle.message("amazonq.refre
2224

2325
// Notify LSP server about all open tabs being removed
2426
val chatManager = ChatCommunicationManager.getInstance(project)
25-
chatManager.getAllTabIds().forEach { tabId ->
26-
AmazonQLspService.executeIfRunning(project) { server ->
27-
rawEndpoint.notify(CHAT_TAB_REMOVE, mapOf("tabId" to tabId))
27+
currentThreadCoroutineScope().launch {
28+
chatManager.getAllTabIds().forEach { tabId ->
29+
AmazonQLspService.executeAsyncIfRunning(project) {
30+
rawEndpoint.notify(CHAT_TAB_REMOVE, mapOf("tabId" to tabId))
31+
}
2832
}
2933
}
3034

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class BrowserConnector(
212212
}
213213
}
214214

215-
private fun handleFlareChatMessages(browser: Browser, node: JsonNode) {
215+
private suspend fun handleFlareChatMessages(browser: Browser, node: JsonNode) {
216216
when (node.command) {
217217
SEND_CHAT_COMMAND_PROMPT -> {
218218
val requestFromUi = serializer.deserializeChatMessages<SendChatPromptRequest>(node)
@@ -234,7 +234,7 @@ class BrowserConnector(
234234
chatCommunicationManager.registerPartialResultToken(partialResultToken)
235235

236236
var encryptionManager: JwtEncryptionManager? = null
237-
val result = AmazonQLspService.executeIfRunning(project) { server ->
237+
val result = AmazonQLspService.executeAsyncIfRunning(project) { server ->
238238
encryptionManager = this.encryptionManager
239239

240240
val encryptedParams = EncryptedChatParams(this.encryptionManager.encrypt(chatParams), partialResultToken)
@@ -254,7 +254,7 @@ class BrowserConnector(
254254
val partialResultToken = chatCommunicationManager.addPartialChatMessage(tabId)
255255
chatCommunicationManager.registerPartialResultToken(partialResultToken)
256256
var encryptionManager: JwtEncryptionManager? = null
257-
val result = AmazonQLspService.executeIfRunning(project) { server ->
257+
val result = AmazonQLspService.executeAsyncIfRunning(project) { server ->
258258
encryptionManager = this.encryptionManager
259259

260260
val encryptedParams = EncryptedQuickActionChatParams(this.encryptionManager.encrypt(quickActionParams), partialResultToken)
@@ -581,7 +581,7 @@ class BrowserConnector(
581581
}
582582
}
583583

584-
private inline fun <reified Request, Response> handleChat(
584+
private suspend inline fun <reified Request, Response> handleChat(
585585
lspMethod: JsonRpcMethod<Request, Response>,
586586
node: JsonNode,
587587
crossinline serverAction: (params: Request, invokeService: () -> CompletableFuture<Response>) -> CompletableFuture<Response>,
@@ -592,7 +592,7 @@ class BrowserConnector(
592592
serializer.deserializeChatMessages<Request>(node.params, lspMethod.params)
593593
}
594594

595-
return AmazonQLspService.executeIfRunning(project) { _ ->
595+
return AmazonQLspService.executeAsyncIfRunning(project) { _ ->
596596
val invokeService = when (lspMethod) {
597597
is JsonRpcNotification<Request> -> {
598598
// notify is Unit
@@ -614,7 +614,7 @@ class BrowserConnector(
614614
} ?: CompletableFuture.failedFuture<Response>(IllegalStateException("LSP Server not running"))
615615
}
616616

617-
private inline fun <reified Request, Response> handleChat(
617+
private suspend inline fun <reified Request, Response> handleChat(
618618
lspMethod: JsonRpcMethod<Request, Response>,
619619
node: JsonNode,
620620
): CompletableFuture<Response> = handleChat(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
187187
CodeWhispererInvocationStatus.getInstance().setInvocationStart()
188188
var nextToken: Either<String, Int>? = null
189189
do {
190-
val result = AmazonQLspService.executeIfRunning(requestContext.project) { server ->
190+
val result = AmazonQLspService.executeAsyncIfRunning(requestContext.project) { server ->
191191
val params = createInlineCompletionParams(requestContext.editor, requestContext.triggerTypeInfo, nextToken)
192192
server.inlineCompletionWithReferences(params)
193193
}
@@ -426,7 +426,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
426426
CodeWhispererTelemetryService.getInstance().sendUserTriggerDecisionEvent(project, latencyContext, sessionId, recommendationContext)
427427
}
428428

429-
fun getRequestContext(
429+
suspend fun getRequestContext(
430430
triggerTypeInfo: TriggerTypeInfo,
431431
editor: Editor,
432432
project: Project,
@@ -472,11 +472,11 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
472472
)
473473
}
474474

475-
fun getWorkspaceIds(project: Project): CompletableFuture<LspServerConfigurations> {
475+
suspend fun getWorkspaceIds(project: Project): CompletableFuture<LspServerConfigurations> {
476476
val payload = GetConfigurationFromServerParams(
477477
section = "aws.q.workspaceContext"
478478
)
479-
return AmazonQLspService.executeIfRunning(project) { server ->
479+
return AmazonQLspService.executeAsyncIfRunning(project) { server ->
480480
server.getConfigurationFromServer(payload)
481481
} ?: (CompletableFuture.failedFuture(IllegalStateException("LSP Server not running")))
482482
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
203203
var requestCount = 0
204204
var nextToken: Either<String, Int>? = null
205205
do {
206-
val result = AmazonQLspService.executeIfRunning(requestContext.project) { server ->
206+
val result = AmazonQLspService.executeAsyncIfRunning(requestContext.project) { server ->
207207
val params = createInlineCompletionParams(requestContext.editor, requestContext.triggerTypeInfo, nextToken)
208208
server.inlineCompletionWithReferences(params)
209209
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.intellij.openapi.options.BoundConfigurable
1010
import com.intellij.openapi.options.Configurable
1111
import com.intellij.openapi.options.SearchableConfigurable
1212
import com.intellij.openapi.options.ex.Settings
13+
import com.intellij.openapi.progress.currentThreadCoroutineScope
1314
import com.intellij.openapi.project.Project
1415
import com.intellij.openapi.project.ProjectManager
1516
import com.intellij.openapi.ui.emptyText
@@ -22,6 +23,8 @@ import com.intellij.ui.dsl.builder.bindText
2223
import com.intellij.ui.dsl.builder.panel
2324
import com.intellij.util.concurrency.EdtExecutorService
2425
import com.intellij.util.execution.ParametersListUtil
26+
import kotlinx.coroutines.launch
27+
import org.eclipse.lsp4j.DidChangeConfigurationParams
2528
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
2629
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
2730
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
@@ -310,7 +313,12 @@ class CodeWhispererConfigurable(private val project: Project) :
310313
if (project.isDisposed) {
311314
return@forEach
312315
}
313-
AmazonQLspService.didChangeConfiguration(project)
316+
317+
currentThreadCoroutineScope().launch {
318+
AmazonQLspService.executeAsyncIfRunning(project) { server ->
319+
server.workspaceService.didChangeConfiguration(DidChangeConfigurationParams())
320+
}
321+
}
314322
}
315323
}
316324
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.telemetry
66
import com.intellij.openapi.components.Service
77
import com.intellij.openapi.components.service
88
import com.intellij.openapi.project.Project
9+
import kotlinx.coroutines.CoroutineScope
10+
import kotlinx.coroutines.launch
911
import software.aws.toolkits.core.utils.debug
1012
import software.aws.toolkits.core.utils.getLogger
1113
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
@@ -33,7 +35,7 @@ import java.time.Duration
3335
import java.time.Instant
3436

3537
@Service
36-
class CodeWhispererTelemetryService {
38+
class CodeWhispererTelemetryService(private val cs: CoroutineScope) {
3739
companion object {
3840
fun getInstance(): CodeWhispererTelemetryService = service()
3941
val LOG = getLogger<CodeWhispererTelemetryService>()
@@ -45,22 +47,24 @@ class CodeWhispererTelemetryService {
4547
sessionId: String,
4648
recommendationContext: RecommendationContext,
4749
) {
48-
AmazonQLspService.executeIfRunning(project) { server ->
49-
val params = LogInlineCompletionSessionResultsParams(
50-
sessionId = sessionId,
51-
completionSessionResult = recommendationContext.details.associate {
52-
it.itemId to InlineCompletionStates(
53-
seen = it.hasSeen,
54-
accepted = it.isAccepted,
55-
discarded = it.isDiscarded
56-
)
57-
},
58-
firstCompletionDisplayLatency = latencyContext.perceivedLatency,
59-
totalSessionDisplayTime = CodeWhispererInvocationStatus.getInstance().completionShownTime?.let { Duration.between(it, Instant.now()) }
60-
?.toMillis()?.toDouble(),
61-
typeaheadLength = recommendationContext.userInput.length.toLong()
62-
)
63-
server.logInlineCompletionSessionResults(params)
50+
cs.launch {
51+
AmazonQLspService.executeAsyncIfRunning(project) { server ->
52+
val params = LogInlineCompletionSessionResultsParams(
53+
sessionId = sessionId,
54+
completionSessionResult = recommendationContext.details.associate {
55+
it.itemId to InlineCompletionStates(
56+
seen = it.hasSeen,
57+
accepted = it.isAccepted,
58+
discarded = it.isDiscarded
59+
)
60+
},
61+
firstCompletionDisplayLatency = latencyContext.perceivedLatency,
62+
totalSessionDisplayTime = CodeWhispererInvocationStatus.getInstance().completionShownTime?.let { Duration.between(it, Instant.now()) }
63+
?.toMillis()?.toDouble(),
64+
typeaheadLength = recommendationContext.userInput.length.toLong()
65+
)
66+
server.logInlineCompletionSessionResults(params)
67+
}
6468
}
6569
}
6670

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryServiceNew.kt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.telemetry
66
import com.intellij.openapi.components.Service
77
import com.intellij.openapi.components.service
88
import com.intellij.openapi.project.Project
9+
import kotlinx.coroutines.CoroutineScope
10+
import kotlinx.coroutines.launch
911
import software.aws.toolkits.core.utils.debug
1012
import software.aws.toolkits.core.utils.getLogger
1113
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
@@ -29,7 +31,7 @@ import java.time.Duration
2931
import java.time.Instant
3032

3133
@Service
32-
class CodeWhispererTelemetryServiceNew {
34+
class CodeWhispererTelemetryServiceNew(private val cs: CoroutineScope) {
3335

3436
companion object {
3537
fun getInstance(): CodeWhispererTelemetryServiceNew = service()
@@ -109,24 +111,26 @@ class CodeWhispererTelemetryServiceNew {
109111
}
110112

111113
fun sendUserTriggerDecisionEvent(project: Project, latencyContext: LatencyContext) {
112-
AmazonQLspService.executeIfRunning(project) { server ->
113-
CodeWhispererServiceNew.getInstance().getAllPaginationSessions().forEach { jobId, state ->
114-
if (state == null) return@forEach
115-
val params = LogInlineCompletionSessionResultsParams(
116-
sessionId = state.responseContext.sessionId,
117-
completionSessionResult = state.recommendationContext.details.associate {
118-
it.itemId to InlineCompletionStates(
119-
seen = it.hasSeen,
120-
accepted = it.isAccepted,
121-
discarded = it.isDiscarded
122-
)
123-
},
124-
firstCompletionDisplayLatency = latencyContext.perceivedLatency,
125-
totalSessionDisplayTime = CodeWhispererInvocationStatus.getInstance().completionShownTime?.let { Duration.between(it, Instant.now()) }
126-
?.toMillis()?.toDouble(),
127-
typeaheadLength = state.recommendationContext.userInput.length.toLong()
128-
)
129-
server.logInlineCompletionSessionResults(params)
114+
cs.launch {
115+
AmazonQLspService.executeAsyncIfRunning(project) { server ->
116+
CodeWhispererServiceNew.getInstance().getAllPaginationSessions().forEach { jobId, state ->
117+
if (state == null) return@forEach
118+
val params = LogInlineCompletionSessionResultsParams(
119+
sessionId = state.responseContext.sessionId,
120+
completionSessionResult = state.recommendationContext.details.associate {
121+
it.itemId to InlineCompletionStates(
122+
seen = it.hasSeen,
123+
accepted = it.isAccepted,
124+
discarded = it.isDiscarded
125+
)
126+
},
127+
firstCompletionDisplayLatency = latencyContext.perceivedLatency,
128+
totalSessionDisplayTime = CodeWhispererInvocationStatus.getInstance().completionShownTime?.let { Duration.between(it, Instant.now()) }
129+
?.toMillis()?.toDouble(),
130+
typeaheadLength = state.recommendationContext.userInput.length.toLong()
131+
)
132+
server.logInlineCompletionSessionResults(params)
133+
}
130134
}
131135
}
132136
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ interface AmazonQLanguageClient : LanguageClient {
4646
fun getSerializedChat(params: LSPAny): CompletableFuture<GetSerializedChatResult>
4747

4848
@JsonNotification(CHAT_SEND_UPDATE)
49-
fun sendChatUpdate(params: LSPAny): CompletableFuture<Unit>
49+
fun sendChatUpdate(params: LSPAny)
5050

5151
@JsonNotification(OPEN_FILE_DIFF)
52-
fun openFileDiff(params: OpenFileDiffParams): CompletableFuture<Unit>
52+
fun openFileDiff(params: OpenFileDiffParams)
5353

5454
@JsonNotification(CHAT_SEND_CONTEXT_COMMANDS)
55-
fun sendContextCommands(params: LSPAny): CompletableFuture<Unit>
55+
fun sendContextCommands(params: LSPAny)
5656

5757
@JsonNotification(DID_COPY_FILE)
5858
fun copyFile(params: CopyFileParams)

0 commit comments

Comments
 (0)