Skip to content

Conversation

@aseemxs
Copy link
Contributor

@aseemxs aseemxs commented Jun 26, 2025

Summary

This PR implements pinned context functionality for Amazon Q Eclipse plugin, allowing users to pin files
to their chat conversations for persistent context. This feature improves the relevance of Amazon Q
responses by maintaining important context throughout the conversation.

What does this PR do?

  • Adds the ability to pin/unpin files in Amazon Q chat conversations
  • Implements automatic active editor tracking with 100ms debouncing
  • Enables the @Pin Context feature visible in the chat UI
  • Provides LSP server integration for pinned context operations

Screenshot

Screenshot 2025-06-26 at 1 05 26 PM

Key Changes

1. Command Infrastructure

  • Added new commands to ChatUIInboundCommandName.java:

    • PinnedContextAdd - Pin a file to the conversation
    • PinnedContextRemove - Unpin a file
    • SendPinnedContext - Send pinned context with chat messages
    • ListRules - List available context rules
    • RuleClick - Handle rule selection
  • Extended Command.java enum with corresponding command values

2. LSP Server Integration

  • Extended AmazonQLspServer.java interface
  • Implemented methods in AmazonQLspClient.java and AmazonQLspClientImpl.java

3. Active Editor Tracking

  • Created ActiveEditorChangeListener.java:
    • Implements IPartListener2 for editor lifecycle events
    • 100ms debouncing to prevent excessive notifications
    • Automatically tracks when users switch between files
    • Registers with all workbench windows

4. Client Capabilities

  • Added pinnedContextEnabled: true flag in AmazonQLspServerBuilder.java
  • Enables pinned context features in the LSP server

5. Command Routing

  • Updated AmazonQChatViewActionHandler.java to route pinned context commands
  • Added cases in ChatCommunicationManager.java for processing commands

Testing Performed

  • ✅ Pin button appears in chat UI as "@pin Context"
  • ✅ Files can be pinned to conversations
  • ✅ Pinned context commands are properly routed to LSP server
  • ✅ Active editor changes are tracked with debouncing
  • ✅ No compilation errors or checkstyle violations
  • ✅ Feature builds successfully with mvn clean install

Known Issues

  • (WIP)

How to Test

  1. Build and run the Eclipse plugin
  2. Open Amazon Q chat view
  3. Look for the "@pin Context" option in the chat interface
  4. Pin a file and send a chat message
  5. Switch between editors and observe active editor tracking
  6. Check logs for pinned context operations

Checklist

  • Code compiles without errors
  • Feature tested locally

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Add pinned context commands to ChatUIInboundCommandName and Command enums
- Implement LSP server methods for pinned context operations
- Add active editor change listener for automatic context tracking
- Enable pinnedContextEnabled flag in client capabilities
- Route pinned context commands through ChatCommunicationManager
- Add support for pinnedContextAdd, pinnedContextRemove, and sendPinnedContext
- Include active editor tracking with 100ms debouncing

This allows users to pin files to chat conversations for persistent context,
improving the relevance of Amazon Q responses.
}

// Schedule a new notification after the debounce period
debounceTask = executor.schedule(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

why debounce?

Map<String, Object> params = new HashMap<>();

if (editor != null) {
IEditorInput editorInput = editor.getEditorInput();
Copy link
Contributor

Choose a reason for hiding this comment

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

there is already logic in QEclipseEditorUtils class to get this information(entirety of this function's logic). Please reuse that instead of creating a new one. We also have logic in addEditorState in ChatCommunicationManager that does something very similar. Please reference these two

public static ActiveEditorChangeListener register(final AmazonQLspServer languageServer, final ScheduledExecutorService executor) {
ActiveEditorChangeListener listener = new ActiveEditorChangeListener(languageServer, executor);

// Register with all workbench windows
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have to register all workbench windows. We only the texteditor right?

}

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

}

@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

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

aseemxs and others added 8 commits June 26, 2025 15:17
- Remove unused imports in ChatCommunicationManager and ActiveEditorChangeListener
- Clean up trailing whitespace in AmazonQLspServer and AmazonQLspClientImpl
- Make ActiveEditorChangeListener final to address DesignForExtension warnings
- Add missing newline at end of ActiveEditorChangeListener.java

All 17 checkstyle violations have been resolved.
The debug log in CHAT_SEND_PROMPT case was causing test failures
by potentially affecting the execution flow. Removed to ensure
chatPartialResultMap.setEntry() is called as expected by tests.
- ActiveEditorChangeListener: Use QEclipseEditorUtils methods instead of duplicating logic
- AmazonQLspClientImpl: Leverage existing editor utilities in sendPinnedContext()
- Simplified window registration logic to focus only on text editors
- Removed ~50 lines of duplicate code across both files
- Fixed remaining checkstyle violations (unused imports, trailing spaces)

Addresses @shruti0085 feedback on code duplication and complexity
@shruti0085
Copy link
Contributor

Closing this in favor of #473

@shruti0085 shruti0085 closed this Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants