Skip to content

Commit 9b03d8e

Browse files
committed
feat(amazonq): support pinned context
1 parent 655ceda commit 9b03d8e

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

packages/amazonq/src/lsp/chat/activation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { window } from 'vscode'
77
import { LanguageClient } from 'vscode-languageclient'
88
import { AmazonQChatViewProvider } from './webviewProvider'
99
import { focusAmazonQPanel, registerCommands } from './commands'
10-
import { registerLanguageServerEventListener, registerMessageListeners } from './messages'
10+
import {
11+
registerActiveEditorChangeListener,
12+
registerLanguageServerEventListener,
13+
registerMessageListeners,
14+
} from './messages'
1115
import { Commands, getLogger, globals, undefinedIfEmpty } from 'aws-core-vscode/shared'
1216
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1317
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
@@ -33,6 +37,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
3337
**/
3438
registerCommands(provider)
3539
registerLanguageServerEventListener(languageClient, provider)
40+
registerActiveEditorChangeListener(languageClient)
3641

3742
provider.onDidResolveWebview(() => {
3843
const disposable = DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { Disposable, LanguageClient, Position, TextDocumentIdentifier } from 'vs
6262
import * as jose from 'jose'
6363
import { AmazonQChatViewProvider } from './webviewProvider'
6464
import { AuthUtil, ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
65-
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
65+
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl, isTextEditor } from 'aws-core-vscode/shared'
6666
import {
6767
DefaultAmazonQAppInitContext,
6868
messageDispatcher,
@@ -74,6 +74,30 @@ import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
7474
import { isValidResponseError } from './error'
7575
import { focusAmazonQPanel } from './commands'
7676

77+
export function registerActiveEditorChangeListener(languageClient: LanguageClient) {
78+
let debounceTimer: NodeJS.Timeout | undefined
79+
vscode.window.onDidChangeActiveTextEditor((editor) => {
80+
if (debounceTimer) {
81+
clearTimeout(debounceTimer)
82+
}
83+
debounceTimer = setTimeout(() => {
84+
let textDocument = undefined
85+
let cursorState = undefined
86+
if (editor) {
87+
textDocument = {
88+
uri: editor.document.uri.toString(),
89+
}
90+
cursorState = getCursorState(editor.selections)
91+
}
92+
// todo: replace with message from lsp once consuming latest language-server-runtimes
93+
languageClient.sendNotification('aws/chat/activeEditorChanged', {
94+
textDocument,
95+
cursorState,
96+
})
97+
}, 100)
98+
})
99+
}
100+
77101
export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
78102
languageClient.info(
79103
'Language client received initializeResult from server:',
@@ -316,6 +340,8 @@ export function registerMessageListeners(
316340
)
317341
break
318342
}
343+
case 'aws/chat/listRules': // todo: switch to imported methods from language-server-runtimes
344+
case 'aws/chat/ruleClick':
319345
case listConversationsRequestType.method:
320346
case conversationClickRequestType.method:
321347
case listMcpServersRequestType.method:
@@ -471,6 +497,20 @@ export function registerMessageListeners(
471497
params: params,
472498
})
473499
})
500+
languageClient.onNotification(
501+
'aws/chat/sendPinnedContext', // todo: switch to type from language-server-runtimes
502+
(params: ContextCommandParams & { tabId: string; textDocument?: TextDocumentIdentifier }) => {
503+
const editor = vscode.window.activeTextEditor
504+
let textDocument = undefined
505+
if (editor && isTextEditor(editor)) {
506+
textDocument = { uri: vscode.workspace.asRelativePath(editor.document.uri) }
507+
}
508+
void provider.webview?.postMessage({
509+
command: 'aws/chat/sendPinnedContext', // todo: switch to type from language-server-runtimes
510+
params: { ...params, textDocument },
511+
})
512+
}
513+
)
474514

475515
languageClient.onNotification(openFileDiffNotificationType.method, async (params: OpenFileDiffParams) => {
476516
const ecc = new EditorContentController()

packages/amazonq/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export async function startLanguageServer(
123123
awsClientCapabilities: {
124124
q: {
125125
developerProfiles: true,
126+
pinnedContextEnabled: true,
126127
mcp: true,
127128
},
128129
window: {

packages/core/src/amazonq/webview/ui/quickActions/handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ export class QuickActionHandler {
362362
cancelButtonWhenLoading: false,
363363
})
364364
} else {
365-
this.mynahUI.updateStore(affectedTabId, { promptInputOptions: [] })
365+
// todo: remove type cast once updated to latest prod mynah that includes promptTopBarTitle
366+
this.mynahUI.updateStore(affectedTabId, { promptInputOptions: [], promptTopBarTitle: '' } as any)
366367
}
367368

368369
if (affectedTabId && this.isHybridChatEnabled) {

packages/core/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export * from './vscode/commands2'
5151
export * from './utilities/pathUtils'
5252
export * from './utilities/zipStream'
5353
export * from './errors'
54+
export { isTextEditor } from './utilities/editorUtilities'
5455
export * as messages from './utilities/messages'
5556
export * as errors from './errors'
5657
export * as funcUtil from './utilities/functionUtils'

0 commit comments

Comments
 (0)