Skip to content

Commit

Permalink
Add threading for the commands and throw AmazonQPluginException for l…
Browse files Browse the repository at this point in the history
…sp communication errors
  • Loading branch information
angjordn committed Sep 19, 2024
1 parent f247cf6 commit 4ff9d04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatRequestParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer;
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
Expand All @@ -20,7 +21,8 @@ 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.");
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider.", e);
throw new AmazonQPluginException(e);
}
}

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

public void sendChatReady() {
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
amazonQLspServer.chatReady();
}

public void sendChatReady() {
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
amazonQLspServer.chatReady();
try {
PluginLogger.info("Sending " + Command.CHAT_READY + " message to Amazon Q LSP server");
amazonQLspServer.chatReady();
} catch (Exception e) {
PluginLogger.error("Error occurred while sending " + Command.CHAT_READY + " message to Amazon Q LSP server", e);
throw new AmazonQPluginException(e);
}
}

public void sendTabAdd(final GenericTabParams tabParams) {
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
amazonQLspServer.tabAdd(tabParams);
try {
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
amazonQLspServer.tabAdd(tabParams);
} catch (Exception e) {
PluginLogger.error("Error occurred while sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server", e);
throw new AmazonQPluginException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public final void createPartControl(final Composite parent) {
new BrowserFunction(browser, "ideCommand") {
@Override
public Object function(final Object[] arguments) {
try {
commandParser.parseCommand(arguments)
.ifPresent(parsedCommand -> actionHandler.handleCommand(parsedCommand, browser));
} catch (Exception e) {
PluginLogger.error("Error processing message from Browser", e);
}
ThreadingUtils.executeAsyncTask(() -> {
try {
commandParser.parseCommand(arguments)
.ifPresent(parsedCommand -> actionHandler.handleCommand(parsedCommand, browser));
} catch (Exception e) {
PluginLogger.error("Error processing message from Browser", e);
}
});
return null;
}
};
Expand Down

0 comments on commit 4ff9d04

Please sign in to comment.