Skip to content
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

Send chat/ready message to lsp and fix addTab issue #24

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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