Skip to content

Commit 4ff9d04

Browse files
committed
Add threading for the commands and throw AmazonQPluginException for lsp communication errors
1 parent f247cf6 commit 4ff9d04

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatMessageProvider.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatRequestParams;
88
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
99
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams;
10+
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
1011
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer;
1112
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
1213
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
@@ -20,7 +21,8 @@ public ChatMessageProvider() {
2021
try {
2122
amazonQLspServer = LspProvider.getAmazonQServer().get();
2223
} catch (InterruptedException | ExecutionException e) {
23-
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider.");
24+
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider.", e);
25+
throw new AmazonQPluginException(e);
2426
}
2527
}
2628

@@ -31,23 +33,27 @@ public ChatResult sendChatPrompt(final ChatRequestParams chatRequestParams) {
3133
return chatResult;
3234
} catch (InterruptedException | ExecutionException e) {
3335
PluginLogger.error("Error occurred while sending " + Command.CHAT_SEND_PROMPT + " message to Amazon Q LSP server", e);
34-
e.printStackTrace();
36+
throw new AmazonQPluginException(e);
3537
}
36-
return null;
3738
}
3839

3940
public void sendChatReady() {
40-
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
41-
amazonQLspServer.chatReady();
42-
}
43-
44-
public void sendChatReady() {
45-
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
46-
amazonQLspServer.chatReady();
41+
try {
42+
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
43+
amazonQLspServer.chatReady();
44+
} catch (Exception e) {
45+
PluginLogger.error("Error occurred while sending " + Command.CHAT_READY + " message to Amazon Q LSP server", e);
46+
throw new AmazonQPluginException(e);
47+
}
4748
}
4849

4950
public void sendTabAdd(final GenericTabParams tabParams) {
50-
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
51-
amazonQLspServer.tabAdd(tabParams);
51+
try {
52+
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
53+
amazonQLspServer.tabAdd(tabParams);
54+
} catch (Exception e) {
55+
PluginLogger.error("Error occurred while sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server", e);
56+
throw new AmazonQPluginException(e);
57+
}
5258
}
5359
}

plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQChatWebview.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ public final void createPartControl(final Composite parent) {
5555
new BrowserFunction(browser, "ideCommand") {
5656
@Override
5757
public Object function(final Object[] arguments) {
58-
try {
59-
commandParser.parseCommand(arguments)
60-
.ifPresent(parsedCommand -> actionHandler.handleCommand(parsedCommand, browser));
61-
} catch (Exception e) {
62-
PluginLogger.error("Error processing message from Browser", e);
63-
}
58+
ThreadingUtils.executeAsyncTask(() -> {
59+
try {
60+
commandParser.parseCommand(arguments)
61+
.ifPresent(parsedCommand -> actionHandler.handleCommand(parsedCommand, browser));
62+
} catch (Exception e) {
63+
PluginLogger.error("Error processing message from Browser", e);
64+
}
65+
});
6466
return null;
6567
}
6668
};

0 commit comments

Comments
 (0)