@@ -55,14 +55,18 @@ import {
55
55
ChatUpdateParams ,
56
56
chatOptionsUpdateType ,
57
57
ChatOptionsUpdateParams ,
58
+ listRulesRequestType ,
59
+ ruleClickRequestType ,
60
+ pinnedContextNotificationType ,
61
+ activeEditorChangedNotificationType ,
58
62
} from '@aws/language-server-runtimes/protocol'
59
63
import { v4 as uuidv4 } from 'uuid'
60
64
import * as vscode from 'vscode'
61
65
import { Disposable , LanguageClient , Position , TextDocumentIdentifier } from 'vscode-languageclient'
62
66
import * as jose from 'jose'
63
67
import { AmazonQChatViewProvider } from './webviewProvider'
64
68
import { 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'
66
70
import {
67
71
DefaultAmazonQAppInitContext ,
68
72
messageDispatcher ,
@@ -74,6 +78,29 @@ import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
74
78
import { isValidResponseError } from './error'
75
79
import { focusAmazonQPanel } from './commands'
76
80
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
+
77
104
export function registerLanguageServerEventListener ( languageClient : LanguageClient , provider : AmazonQChatViewProvider ) {
78
105
languageClient . info (
79
106
'Language client received initializeResult from server:' ,
@@ -316,6 +343,8 @@ export function registerMessageListeners(
316
343
)
317
344
break
318
345
}
346
+ case listRulesRequestType . method :
347
+ case ruleClickRequestType . method :
319
348
case listConversationsRequestType . method :
320
349
case conversationClickRequestType . method :
321
350
case listMcpServersRequestType . method :
@@ -471,6 +500,20 @@ export function registerMessageListeners(
471
500
params : params ,
472
501
} )
473
502
} )
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
+ )
474
517
475
518
languageClient . onNotification ( openFileDiffNotificationType . method , async ( params : OpenFileDiffParams ) => {
476
519
const ecc = new EditorContentController ( )
0 commit comments