-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make command handling in Q chat webview async #35
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
package software.aws.toolkits.eclipse.amazonq.chat; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatRequestParams; | ||
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult; | ||
|
@@ -15,25 +15,24 @@ | |
|
||
public final class ChatMessageProvider { | ||
|
||
private AmazonQLspServer amazonQLspServer; | ||
private final AmazonQLspServer amazonQLspServer; | ||
|
||
public ChatMessageProvider() { | ||
try { | ||
amazonQLspServer = LspProvider.getAmazonQServer().get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider.", e); | ||
throw new AmazonQPluginException(e); | ||
} | ||
public static CompletableFuture<ChatMessageProvider> createAsync() { | ||
return LspProvider.getAmazonQServer() | ||
.thenApply(ChatMessageProvider::new); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh I see. That makes sense. |
||
} | ||
|
||
private ChatMessageProvider(AmazonQLspServer amazonQLspServer) { | ||
this.amazonQLspServer = amazonQLspServer; | ||
} | ||
|
||
public ChatResult sendChatPrompt(final ChatRequestParams chatRequestParams) { | ||
public CompletableFuture<ChatResult> sendChatPrompt(final ChatRequestParams chatRequestParams) { | ||
try { | ||
PluginLogger.info("Sending " + Command.CHAT_SEND_PROMPT + " message to Amazon Q LSP server"); | ||
ChatResult chatResult = amazonQLspServer.sendChatPrompt(chatRequestParams).get(); | ||
return chatResult; | ||
} catch (InterruptedException | ExecutionException e) { | ||
return amazonQLspServer.sendChatPrompt(chatRequestParams); | ||
} catch (Exception e) { | ||
PluginLogger.error("Error occurred while sending " + Command.CHAT_SEND_PROMPT + " message to Amazon Q LSP server", e); | ||
throw new AmazonQPluginException(e); | ||
return CompletableFuture.failedFuture(new AmazonQPluginException(e)); | ||
} | ||
} | ||
|
||
|
@@ -56,4 +55,5 @@ public void sendTabAdd(final GenericTabParams tabParams) { | |
throw new AmazonQPluginException(e); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.