@@ -62,7 +62,7 @@ import { Disposable, LanguageClient, Position, TextDocumentIdentifier } from 'vs
6262import * as jose from 'jose'
6363import { AmazonQChatViewProvider } from './webviewProvider'
6464import { 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'
6666import {
6767 DefaultAmazonQAppInitContext ,
6868 messageDispatcher ,
@@ -74,6 +74,30 @@ import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
7474import { isValidResponseError } from './error'
7575import { 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+
77101export 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 ( )
0 commit comments