Skip to content

Commit

Permalink
Send chat/ready message to lsp and fix addTab issue (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
angjordn authored Sep 18, 2024
1 parent 4e89698 commit 01569db
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
public final class ChatCommunicationManager {

private final JsonHandler jsonHandler;
private final ChatMessageProvider chatMessageProivder;
private final ChatMessageProvider chatMessageProvider;

public ChatCommunicationManager() {
this.jsonHandler = new JsonHandler();
this.chatMessageProivder = new ChatMessageProvider();
this.chatMessageProvider = new ChatMessageProvider();
}

public void sendMessageToChatServerAsync(final Command command, final Object params) {

String jsonParams = jsonHandler.serialize(params);

switch (command) {
case CHAT_READY:
chatMessageProvider.sendChatReady();
break;
case CHAT_TAB_ADD:
GenericTabParams tabParams = jsonHandler.deserialize(jsonParams, GenericTabParams.class);
chatMessageProivder.sendTabAdd(tabParams);
chatMessageProvider.sendTabAdd(tabParams);
break;
default:
PluginLogger.error("Unhandled chat command: " + command.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public ChatMessageProvider() {
}
}

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

public void sendTabAdd(final GenericTabParams tabParams) {
try {
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
amazonQLspServer.tabAdd(tabParams).get();
} catch (InterruptedException | ExecutionException e) {
PluginLogger.error("Error occurred while sending message to Amazon Q LSP server for command " + Command.CHAT_TAB_ADD);
}
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
amazonQLspServer.tabAdd(tabParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.services.LanguageServer;

import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.InlineCompletionParams;
import software.aws.toolkits.eclipse.amazonq.lsp.model.InlineCompletionResponse;
Expand All @@ -21,7 +20,10 @@ public interface AmazonQLspServer extends LanguageServer {
CompletableFuture<InlineCompletionResponse> inlineCompletionWithReferences(InlineCompletionParams params);

@JsonNotification("aws/chat/tabAdd")
CompletableFuture<ChatResult> tabAdd(GenericTabParams params);
void tabAdd(GenericTabParams params);

@JsonNotification("aws/chat/ready")
void chatReady();

@JsonRequest("aws/credentials/token/update")
CompletableFuture<ResponseMessage> updateTokenCredentials(UpdateCredentialsPayload payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser

switch (command) {
case CHAT_READY:
chatCommunicationManager.sendMessageToChatServerAsync(command, params);
break;
case CHAT_TAB_ADD:
chatCommunicationManager.sendMessageToChatServerAsync(command, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import jakarta.inject.Inject;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspConstants;
import software.aws.toolkits.eclipse.amazonq.util.AuthUtils;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;
import software.aws.toolkits.eclipse.amazonq.views.actions.AmazonQCommonActions;
Expand Down Expand Up @@ -54,8 +55,12 @@ public final void createPartControl(final Composite parent) {
new BrowserFunction(browser, "ideCommand") {
@Override
public Object function(final Object[] arguments) {
commandParser.parseCommand(arguments)
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 01569db

Please sign in to comment.