Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -41,6 +41,7 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.ErrorParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.ReferenceTrackerInformation;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer;
import software.aws.toolkits.eclipse.amazonq.lsp.encryption.DefaultLspEncryptionManager;
import software.aws.toolkits.eclipse.amazonq.lsp.encryption.LspEncryptionManager;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
Expand Down Expand Up @@ -128,6 +129,8 @@ public void sendMessageToChatServer(final Command command, final ChatMessage mes
switch (command) {
case CHAT_SEND_PROMPT:
message.addValueForKey("context", message.getValueForKey("prompt.context"));
// Log the message data to see if pinnedContext is included
Activator.getLogger().info("CHAT_SEND_PROMPT message data: " + message.getData());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this log

addEditorState(message, true);
sendEncryptedChatMessage(message.getValueAsString("tabId"), token -> {
String encryptedMessage = lspEncryptionManager.encrypt(message.getData());
Expand Down Expand Up @@ -258,6 +261,50 @@ public void sendMessageToChatServer(final Command command, final ChatMessage mes
Activator.getLogger().error("Error processing mcpServerClick: " + e);
}
break;
case LIST_RULES:
try {
Object listRulesResponse = amazonQLspServer.listRules(message.getData()).get();
var listRulesCommand = ChatUIInboundCommand.createCommand("aws/chat/listRules",
listRulesResponse);
Activator.getEventBroker().post(ChatUIInboundCommand.class, listRulesCommand);
} catch (Exception e) {
Activator.getLogger().error("Error processing listRules: " + e);
}
break;
case RULE_CLICK:
try {
Object ruleClickResponse = amazonQLspServer.ruleClick(message.getData()).get();
var ruleClickCommand = ChatUIInboundCommand.createCommand("aws/chat/ruleClick",
ruleClickResponse);
Activator.getEventBroker().post(ChatUIInboundCommand.class, ruleClickCommand);
} catch (Exception e) {
Activator.getLogger().error("Error processing ruleClick: " + e);
}
break;
case PINNED_CONTEXT_ADD:
try {
Activator.getLogger().info("Pinned Context: Processing add command with data: " + message.getData());
amazonQLspServer.pinnedContextAdd(message.getData());
} catch (Exception e) {
Activator.getLogger().error("Pinned Context: Error processing add command: " + e);
}
break;
case PINNED_CONTEXT_REMOVE:
try {
Activator.getLogger().info("Pinned Context: Processing remove command");
amazonQLspServer.pinnedContextRemove(message.getData());
} catch (Exception e) {
Activator.getLogger().error("Pinned Context: Error processing remove command: " + e);
}
break;
case SEND_PINNED_CONTEXT:
try {
Activator.getLogger().info("Pinned Context: Processing send command");
amazonQLspServer.sendPinnedContext(message.getData());
} catch (Exception e) {
Activator.getLogger().error("Pinned Context: Error processing send command: " + e);
}
break;
default:
throw new AmazonQPluginException("Unexpected command received from Chat UI: " + command.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public enum ChatUIInboundCommandName {
GenericCommand("genericCommand"),
ChatOptionsUpdate("aws/chat/chatOptionsUpdate"),
ListMcpServers("aws/chat/listMcpServers"),
McpServerClick("aws/chat/mcpServerClick");
McpServerClick("aws/chat/mcpServerClick"),
ListRules("aws/chat/listRules"),
RuleClick("aws/chat/ruleClick"),
PinnedContextAdd("aws/chat/pinnedContextAdd"),
PinnedContextRemove("aws/chat/pinnedContextRemove"),
SendPinnedContext("aws/chat/sendPinnedContext");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ public interface AmazonQLspClient extends LanguageClient {
@JsonNotification("aws/didCreateDirectory")
void didCreateDirectory(Object params);

@JsonNotification("aws/chat/sendPinnedContext")
void sendPinnedContext(Object params);

@JsonNotification("aws/chat/activeEditorChanged")
void activeEditorChanged(Object params);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -44,7 +45,9 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPageListener;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
Expand Down Expand Up @@ -575,4 +578,72 @@ private boolean isUriInWorkspace(final String uri) {
return false;
}
}

@Override
public final void sendPinnedContext(final Object params) {
Activator.getLogger().info("Pinned Context: sendPinnedContext called with params: " + params);

// Get current active editor and add textDocument information
IEditorPart activeEditor = null;
try {
var workbench = PlatformUI.getWorkbench();
if (workbench != null) {
var activeWindow = workbench.getActiveWorkbenchWindow();
if (activeWindow != null) {
var activePage = activeWindow.getActivePage();
if (activePage != null) {
activeEditor = activePage.getActiveEditor();
}
}
}
} catch (Exception e) {
Activator.getLogger().warn("Could not get active editor: " + e.getMessage());
}

Object updatedParams = params;
if (activeEditor != null && activeEditor instanceof ITextEditor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is also the same as previous comment. Same comment applies here.If needed try to use or extend existing logic to achieve the same instead of de-dup in

ITextEditor textEditor = (ITextEditor) activeEditor;
IEditorInput editorInput = textEditor.getEditorInput();

if (editorInput instanceof IFileEditorInput) {
IFileEditorInput fileInput = (IFileEditorInput) editorInput;
IFile file = fileInput.getFile();

// Create textDocument with workspace-relative path if in workspace, absolute otherwise
String uri;
if (file.getWorkspace().getRoot().exists(file.getFullPath())) {
uri = file.getFullPath().toString();
} else {
uri = file.getLocation().toString();
}

Map<String, Object> textDocument = new HashMap<>();
textDocument.put("uri", uri);

if (params instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> paramsMap = new HashMap<>((Map<String, Object>) params);
paramsMap.put("textDocument", textDocument);
updatedParams = paramsMap;
} else {
Map<String, Object> wrappedParams = new HashMap<>();
wrappedParams.put("params", params);
wrappedParams.put("textDocument", textDocument);
updatedParams = wrappedParams;
}
}
}

var sendPinnedContextCommand = new ChatUIInboundCommand("aws/chat/sendPinnedContext", null, updatedParams,
false, null);
Activator.getEventBroker().post(ChatUIInboundCommand.class, sendPinnedContextCommand);
}

@Override
public final void activeEditorChanged(final Object params) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this been added here if its not implemented yet

// This notification is sent from Eclipse to server when editor changes
// In Phase 3, this will be handled by the ActiveEditorChangeListener
// For now, just log it
Activator.getLogger().info("Active editor changed notification received: " + params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,22 @@ <T extends Configuration> CompletableFuture<LspServerConfigurations<T>> getConfi

@JsonRequest("aws/chat/mcpServerClick")
CompletableFuture<Object> mcpServerClick(Object params);

@JsonRequest("aws/chat/listRules")
CompletableFuture<Object> listRules(Object params);

@JsonRequest("aws/chat/ruleClick")
CompletableFuture<Object> ruleClick(Object params);

@JsonNotification("aws/chat/pinnedContextAdd")
void pinnedContextAdd(Object params);

@JsonNotification("aws/chat/pinnedContextRemove")
void pinnedContextRemove(Object params);

@JsonNotification("aws/chat/sendPinnedContext")
void sendPinnedContext(Object params);

@JsonNotification("aws/chat/activeEditorChanged")
void activeEditorChanged(Object params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private Map<String, Object> getInitializationOptions(final ClientMetadata metada
qOptions.put("developerProfiles", true);
qOptions.put("customizationsWithMetadata", true);
qOptions.put("mcp", true);
qOptions.put("pinnedContextEnabled", true);
awsClientCapabilities.put("q", qOptions);
Map<String, Object> window = new HashMap<>();
window.put("showSaveFileDialog", true);
Expand Down
Loading
Loading