Skip to content

Conversation

shruti0085
Copy link
Contributor

@shruti0085 shruti0085 commented Jul 1, 2025

Description of changes:

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

This change also remove the isUriInWorkspace check for when lsp sends showDocument notification to client. This check would gate the ability to open documents not present in the workspace which is required for paths associated with prompts/rules are stored on disk and require opening it in the IDE for editing

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

QEclipseEditorUtils.getSelectionRange(editor).ifPresent(range -> {
Map<String, Object> cursorState = new HashMap<>();
cursorState.put("range", range);
params.put("cursorState", cursorState);

Choose a reason for hiding this comment

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

Should this put an explicit null if the selection range isn't present, like the else branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, we can skip it.

Comment on lines +50 to +52
if (debounceTask != null) {
debounceTask.cancel(true);
}

Choose a reason for hiding this comment

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

Dumb question, but is there a case where actively cancelling debounces could end up running into whatever throttling problem the debounce tasks is supposed to prevent against?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, intention is to handle too many active editor switching user may perform. Cancel will only cancel the scheduled task which is supposed to execute 100ms after, which means the lsp notification would not have been sent to be throttled anyway.

var lspServer = Activator.getLspProvider().getAmazonQServer().get();
lspServer.activeEditorChanged(params);
} catch (Exception e) {
Activator.getLogger().error("Failed to send active editor changed notification", e);

Choose a reason for hiding this comment

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

Should the catch end the debounce task?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that is not necessary. The task will end naturally as its already in progress and does not need cancelling.

.map(this::getRelativePath);
}

private String getRelativePath(final String absoluteUri) {

Choose a reason for hiding this comment

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

Is there a library that can handle this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not one I could find at this time.

Copy link

Choose a reason for hiding this comment

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

maybe Path#relativize

private static ActiveEditorChangeListener instance;
private static final long DEBOUNCE_DELAY_MS = 100L;
private ScheduledFuture<?> debounceTask;
private org.eclipse.ui.IWorkbenchWindow registeredWindow;
Copy link

Choose a reason for hiding this comment

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

Suggested change
private org.eclipse.ui.IWorkbenchWindow registeredWindow;
private WorkbenchWindow registeredWindow;

@shruti0085 shruti0085 merged commit df41895 into main Jul 9, 2025
1 check passed
@shruti0085 shruti0085 deleted the shruti0085/pinnedContext branch July 9, 2025 16:49
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.

3 participants