generated from amazon-archives/__template_Apache-2.0
-
Couldn't load subscription status.
- Fork 10
feat: Add pinned context support for Amazon Q chat #470
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d4ae92b
feat: Add pinned context support for Amazon Q chat
aseemxs 1d99736
fix: Resolve checkstyle violations for pinned context feature
aseemxs bcc8485
fix: Remove debug log that was interfering with tests
aseemxs c1a04b7
Refactor: Address PR review comments - reuse existing utilities
aseemxs a21ce93
Delete setup_mcp_server.sh
aseemxs cdd8212
Delete .amazonq/rules/Aseem.md
aseemxs 8312da9
Delete .amazonq/rules/Shruit.md
aseemxs fe99263
Delete CLAUDE.md
aseemxs 142dfd0
Delete Eclipse.log
aseemxs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/editor/ActiveEditorChangeListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.eclipse.amazonq.lsp.editor; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.ScheduledFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.eclipse.ui.IPartListener2; | ||
| import org.eclipse.ui.IWorkbenchPartReference; | ||
| import org.eclipse.ui.PlatformUI; | ||
| import org.eclipse.ui.texteditor.ITextEditor; | ||
|
|
||
| import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer; | ||
| import software.aws.toolkits.eclipse.amazonq.plugin.Activator; | ||
| import software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils; | ||
|
|
||
| /** | ||
| * Listens for active editor changes and notifies the language server | ||
| * with debouncing to avoid excessive notifications. | ||
| */ | ||
| public final class ActiveEditorChangeListener implements IPartListener2 { | ||
| private static final long DEBOUNCE_DELAY_MS = 100L; | ||
|
|
||
| private final AmazonQLspServer languageServer; | ||
| private final ScheduledExecutorService executor; | ||
| private ScheduledFuture<?> debounceTask; | ||
|
|
||
| public ActiveEditorChangeListener(final AmazonQLspServer languageServer, final ScheduledExecutorService executor) { | ||
| this.languageServer = languageServer; | ||
| this.executor = executor; | ||
| } | ||
|
|
||
| @Override | ||
| public void partActivated(final IWorkbenchPartReference partRef) { | ||
| if (partRef.getPart(false) instanceof ITextEditor) { | ||
| handleEditorChange((ITextEditor) partRef.getPart(false)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void partBroughtToTop(final IWorkbenchPartReference partRef) { | ||
| if (partRef.getPart(false) instanceof ITextEditor) { | ||
| handleEditorChange((ITextEditor) partRef.getPart(false)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void partClosed(final IWorkbenchPartReference partRef) { | ||
| // When editor is closed, send notification with null values | ||
| handleEditorChange(null); | ||
| } | ||
|
|
||
| @Override | ||
| public void partDeactivated(final IWorkbenchPartReference partRef) { | ||
| // No action needed | ||
| } | ||
|
|
||
| @Override | ||
| public void partOpened(final IWorkbenchPartReference partRef) { | ||
| if (partRef.getPart(false) instanceof ITextEditor) { | ||
| handleEditorChange((ITextEditor) partRef.getPart(false)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void partHidden(final IWorkbenchPartReference partRef) { | ||
| // No action needed | ||
| } | ||
|
|
||
| @Override | ||
| public void partVisible(final IWorkbenchPartReference partRef) { | ||
| if (partRef.getPart(false) instanceof ITextEditor) { | ||
| handleEditorChange((ITextEditor) partRef.getPart(false)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void partInputChanged(final IWorkbenchPartReference partRef) { | ||
| if (partRef.getPart(false) instanceof ITextEditor) { | ||
| handleEditorChange((ITextEditor) partRef.getPart(false)); | ||
| } | ||
| } | ||
|
|
||
| private void handleEditorChange(final ITextEditor editor) { | ||
| // Cancel any pending notification | ||
| if (debounceTask != null) { | ||
| debounceTask.cancel(false); | ||
| } | ||
|
|
||
| // Schedule a new notification after the debounce period | ||
| debounceTask = executor.schedule(() -> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why debounce? |
||
| try { | ||
| Map<String, Object> params = createActiveEditorParams(editor); | ||
|
|
||
| // Send notification to language server | ||
| languageServer.activeEditorChanged(params); | ||
| Activator.getLogger().info("Active editor changed notification sent: " | ||
| + (editor != null ? editor.getTitle() : "no editor")); | ||
|
|
||
| } catch (Exception e) { | ||
| Activator.getLogger().error("Failed to send active editor changed notification", e); | ||
| } | ||
| }, DEBOUNCE_DELAY_MS, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| private Map<String, Object> createActiveEditorParams(final ITextEditor editor) { | ||
| Map<String, Object> params = new HashMap<>(); | ||
|
|
||
| if (editor != null) { | ||
| // Use existing utility to get file URI | ||
| Optional<String> fileUri = QEclipseEditorUtils.getOpenFileUri(editor.getEditorInput()); | ||
| if (fileUri.isPresent()) { | ||
| Map<String, String> textDocument = new HashMap<>(); | ||
| textDocument.put("uri", fileUri.get()); | ||
| params.put("textDocument", textDocument); | ||
|
|
||
| // Use existing utility to get cursor state - but only if this editor is the active one | ||
| if (editor == QEclipseEditorUtils.getActiveTextEditor()) { | ||
| QEclipseEditorUtils.getActiveSelectionRange().ifPresent(range -> { | ||
| Map<String, Object> cursorState = new HashMap<>(); | ||
| cursorState.put("range", range); | ||
| params.put("cursorState", cursorState); | ||
| }); | ||
| } | ||
| } | ||
| } else { | ||
| // Editor is null (closed), send null values | ||
| params.put("textDocument", null); | ||
| params.put("cursorState", null); | ||
| } | ||
|
|
||
| return params; | ||
| } | ||
|
|
||
| /** | ||
| * Register the listener with the workbench. | ||
| */ | ||
| public static ActiveEditorChangeListener register(final AmazonQLspServer languageServer, final ScheduledExecutorService executor) { | ||
| ActiveEditorChangeListener listener = new ActiveEditorChangeListener(languageServer, executor); | ||
|
|
||
| // Register with the current active workbench window | ||
| if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { | ||
| PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(listener); | ||
| } | ||
|
|
||
| // Register with any new windows that open | ||
| PlatformUI.getWorkbench().addWindowListener(new org.eclipse.ui.IWindowListener() { | ||
| @Override | ||
| public void windowOpened(final org.eclipse.ui.IWorkbenchWindow window) { | ||
| window.getPartService().addPartListener(listener); | ||
| } | ||
|
|
||
| @Override | ||
| public void windowClosed(final org.eclipse.ui.IWorkbenchWindow window) { | ||
| window.getPartService().removePartListener(listener); | ||
| } | ||
|
|
||
| @Override | ||
| public void windowActivated(final org.eclipse.ui.IWorkbenchWindow window) { | ||
| // No action needed | ||
| } | ||
|
|
||
| @Override | ||
| public void windowDeactivated(final org.eclipse.ui.IWorkbenchWindow window) { | ||
| // No action needed | ||
| } | ||
| }); | ||
|
|
||
| return listener; | ||
| } | ||
|
|
||
| /** | ||
| * Unregister the listener. | ||
| */ | ||
| public void dispose() { | ||
| if (debounceTask != null) { | ||
| debounceTask.cancel(true); | ||
| } | ||
|
|
||
| // Remove from current workbench windows | ||
| for (org.eclipse.ui.IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { | ||
| window.getPartService().removePartListener(this); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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