-
Notifications
You must be signed in to change notification settings - Fork 272
feat(amazonq): enable pinned context and rules management #5845
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
Conversation
ef1abbd
to
d738646
Compare
...ains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQChatServer.kt
Fixed
Show fixed
Hide fixed
...rc/software/aws/toolkits/jetbrains/services/amazonq/lsp/editor/ActiveEditorChangeListener.kt
Fixed
Show fixed
Hide fixed
...rc/software/aws/toolkits/jetbrains/services/amazonq/lsp/editor/ActiveEditorChangeListener.kt
Fixed
Show fixed
Hide fixed
val chatManager = ChatCommunicationManager.getInstance(project) | ||
|
||
// Get the active text editor and create text document identifier | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor |
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.
Would recommend creating utils for this since the same util is being used while sending chat prompts in LspEditorUtils
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.
this behaves differently from when we send chat prompt, since here we want to send the relative path to the active file. the only common call is FileEditorManager.getInstance(project).selectedTextEditor
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.
we will eventually need to ban selectedTextEditor
but that can be done later
// Get the active text editor and create text document identifier | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor | ||
val textDocument = editor?.let { | ||
TextDocumentIdentifier(it.virtualFile.path) |
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.
We are sending the URI in chat prompt, maybe we can follow the same implementation here, re: the comment above
} | ||
|
||
// Register active editor change listener | ||
val executor = java.util.concurrent.Executors.newSingleThreadScheduledExecutor { r -> |
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.
Can this be handled as part of TextDocumentServiceHandler?
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.
Oh great! Im gonna try getting rid of the new ActiveEditorChangeListener.kt I added and just adding an override in TextDocumentServiceHandler
|
||
private fun handleActiveEditorChange(file: VirtualFile?, editor: Editor?) { | ||
// Cancel any pending notification | ||
debounceTask?.cancel(false) |
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.
Curious, does this handle the case when multiple windows are opened for the same project?
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.
Looks like its only invoked for files in the primary window. but not worried about it
...munity/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt
Outdated
Show resolved
Hide resolved
* Concrete implementation of [AmazonQLanguageClient] to handle messages sent from server | ||
*/ | ||
class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageClient { | ||
private val chatManager = ChatCommunicationManager.getInstance(project) |
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.
services should be lazy init
private val chatManager = ChatCommunicationManager.getInstance(project) | |
private val chatManager | |
get() = ChatCommunicationManager.getInstance(project) |
mutableParams["textDocument"] = textDocument | ||
mutableParams | ||
} | ||
else -> mapOf( |
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.
will it ever hit this case or is it always a map?
private val mockChatManager = mockk<ChatCommunicationManager>(relaxed = true) | ||
private val sut: AmazonQLanguageClientImpl | ||
|
||
init { |
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.
is this still needed with the proposed getter change? prefer ProjectExtension
/replaceService
over mocking projects and getService() calls
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.
Removed
@JsonNotification(CHAT_SEND_PINNED_CONTEXT) | ||
fun sendPinnedContext(params: LSPAny): CompletableFuture<Unit> | ||
|
||
@JsonNotification(CHAT_PINNED_CONTEXT_ADD) | ||
fun pinnedContextAdd(params: LSPAny): CompletableFuture<Unit> | ||
|
||
@JsonNotification(CHAT_PINNED_CONTEXT_REMOVE) | ||
fun pinnedContextRemove(params: LSPAny): CompletableFuture<Unit> |
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.
@JsonNotification(CHAT_SEND_PINNED_CONTEXT) | |
fun sendPinnedContext(params: LSPAny): CompletableFuture<Unit> | |
@JsonNotification(CHAT_PINNED_CONTEXT_ADD) | |
fun pinnedContextAdd(params: LSPAny): CompletableFuture<Unit> | |
@JsonNotification(CHAT_PINNED_CONTEXT_REMOVE) | |
fun pinnedContextRemove(params: LSPAny): CompletableFuture<Unit> | |
@JsonNotification(CHAT_SEND_PINNED_CONTEXT) | |
fun sendPinnedContext(params: LSPAny) | |
@JsonNotification(CHAT_PINNED_CONTEXT_ADD) | |
fun pinnedContextAdd(params: LSPAny) | |
@JsonNotification(CHAT_PINNED_CONTEXT_REMOVE) | |
fun pinnedContextRemove(params: LSPAny) |
9fd6d13
to
7eb55a4
Compare
Types of changes
Description
This PR enables the pinned context feature in Amazon Q chat. Equivalent vs code PR: aws/aws-toolkit-vscode#7493
Key Changes
1. Override selectionChanged in TextDocumentServiceHandler.kt
• Sends ACTIVE_EDITOR_CHANGED_NOTIFICATION notification to server when file editor selection changes
• Purpose: When server receives ACTIVE_EDITOR_CHANGED_NOTIFICATION, it sends a sendPinnedContext message back to the client so the "Active file" pinned context item shows the path of the active file
2. New Message Types and Commands
Pinned Context Support:
• CHAT_PINNED_CONTEXT_ADD - Sent to server when user adds item to pinned context
• CHAT_PINNED_CONTEXT_REMOVE - Sent to server when user remove item from pinned context
• CHAT_SEND_PINNED_CONTEXT - Sent to client with list of pinned context items & current active file info
• ACTIVE_EDITOR_CHANGED_NOTIFICATION - Notify server when active file changes
Rules Management:
• LIST_RULES_REQUEST_METHOD - Sent to server to retrieve available workspace rules
• RULE_CLICK_REQUEST_METHOD - Sent to server to handle workspace rule opt in/opt out
3. Client Capabilities Enhancement
• Updated ExtendedClientMetadata to include
pinnedContextEnabled: true
capability. This is the feature flag that enables the pinned context feature to be displayed in client.• Enhanced CreatePromptParams to support rule creation with isRule parameter. This enables rule creation with the existing CreatePrompt message
• Updated
addTab
in quick actions handler to clearpromptTopBarTitle
. This prevents pinned context tab from staying visible when user clicks /dev, /doc, etc4. Dependency Updates
• Updated @aws/mynah-ui from 4.30.3 to 4.35.5
• Updated @aws/chat-client from 0.1.4 to 0.1.18
Checklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.