Skip to content

Make command handling in Q chat webview async - #35

Merged
breedloj merged 2 commits into
mainfrom
breedloj/asyncChatCommands
Sep 25, 2024
Merged

Make command handling in Q chat webview async#35
breedloj merged 2 commits into
mainfrom
breedloj/asyncChatCommands

Conversation

@breedloj

Copy link
Copy Markdown
Contributor

Description of changes:
I ran into an issue where the call to get the Q LSP was creating a deadlock in the IDE's ability to fetch and start the language server. Any LSP dependencies should be async/handled in a separate thread. This change makes communication with the chat LSP async.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


public ChatMessageProvider() {
try {
amazonQLspServer = LspProvider.getAmazonQServer().get();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this the root cause of the deadlock between the LSP and Client startup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this blocking call was preventing download and startup from happening.

}
public static CompletableFuture<ChatMessageProvider> createAsync() {
return LspProvider.getAmazonQServer()
.thenApply(ChatMessageProvider::new);

@dingfeli dingfeli Sep 25, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be the root of the change. Not entirely familiar with how JVM handles async but is thenApply thread safe somehow? How does it prevent deadlock in this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thenApply runs once the future is resolved. Primary thing here is to avoid a blocking call in the constructor run on the main thread. This pattern gives consumers a way to safely construct an instance in an async flow by making the resolution explicit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I see. That makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants