@@ -55,14 +55,18 @@ import {
5555 ChatUpdateParams ,
5656 chatOptionsUpdateType ,
5757 ChatOptionsUpdateParams ,
58+ listRulesRequestType ,
59+ ruleClickRequestType ,
60+ pinnedContextNotificationType ,
61+ activeEditorChangedNotificationType ,
5862} from '@aws/language-server-runtimes/protocol'
5963import { v4 as uuidv4 } from 'uuid'
6064import * as vscode from 'vscode'
6165import { Disposable , LanguageClient , Position , TextDocumentIdentifier } from 'vscode-languageclient'
6266import * as jose from 'jose'
6367import { AmazonQChatViewProvider } from './webviewProvider'
6468import { AuthUtil , ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
65- import { amazonQDiffScheme , AmazonQPromptSettings , messages , openUrl } from 'aws-core-vscode/shared'
69+ import { amazonQDiffScheme , AmazonQPromptSettings , messages , openUrl , isTextEditor } from 'aws-core-vscode/shared'
6670import {
6771 DefaultAmazonQAppInitContext ,
6872 messageDispatcher ,
@@ -74,6 +78,29 @@ import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
7478import { isValidResponseError } from './error'
7579import { focusAmazonQPanel } from './commands'
7680
81+ export function registerActiveEditorChangeListener ( languageClient : LanguageClient ) {
82+ let debounceTimer : NodeJS . Timeout | undefined
83+ vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
84+ if ( debounceTimer ) {
85+ clearTimeout ( debounceTimer )
86+ }
87+ debounceTimer = setTimeout ( ( ) => {
88+ let textDocument = undefined
89+ let cursorState = undefined
90+ if ( editor ) {
91+ textDocument = {
92+ uri : editor . document . uri . toString ( ) ,
93+ }
94+ cursorState = getCursorState ( editor . selections )
95+ }
96+ languageClient . sendNotification ( activeEditorChangedNotificationType . method , {
97+ textDocument,
98+ cursorState,
99+ } )
100+ } , 100 )
101+ } )
102+ }
103+
77104export function registerLanguageServerEventListener ( languageClient : LanguageClient , provider : AmazonQChatViewProvider ) {
78105 languageClient . info (
79106 'Language client received initializeResult from server:' ,
@@ -316,6 +343,8 @@ export function registerMessageListeners(
316343 )
317344 break
318345 }
346+ case listRulesRequestType . method :
347+ case ruleClickRequestType . method :
319348 case listConversationsRequestType . method :
320349 case conversationClickRequestType . method :
321350 case listMcpServersRequestType . method :
@@ -471,6 +500,20 @@ export function registerMessageListeners(
471500 params : params ,
472501 } )
473502 } )
503+ languageClient . onNotification (
504+ pinnedContextNotificationType . method ,
505+ ( params : ContextCommandParams & { tabId : string ; textDocument ?: TextDocumentIdentifier } ) => {
506+ const editor = vscode . window . activeTextEditor
507+ let textDocument = undefined
508+ if ( editor && isTextEditor ( editor ) ) {
509+ textDocument = { uri : vscode . workspace . asRelativePath ( editor . document . uri ) }
510+ }
511+ void provider . webview ?. postMessage ( {
512+ command : pinnedContextNotificationType . method ,
513+ params : { ...params , textDocument } ,
514+ } )
515+ }
516+ )
474517
475518 languageClient . onNotification ( openFileDiffNotificationType . method , async ( params : OpenFileDiffParams ) => {
476519 const ecc = new EditorContentController ( )
0 commit comments