@@ -55,13 +55,17 @@ 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 { AmazonQChatViewProvider } from './webviewProvider'
63
- import { AuthUtil , CodeWhispererSettings , ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
64
- import { amazonQDiffScheme , AmazonQPromptSettings , messages , openUrl } from 'aws-core-vscode/shared'
67
+ import { AuthUtil , ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
68
+ import { amazonQDiffScheme , AmazonQPromptSettings , messages , openUrl , isTextEditor } from 'aws-core-vscode/shared'
65
69
import {
66
70
DefaultAmazonQAppInitContext ,
67
71
messageDispatcher ,
@@ -75,6 +79,29 @@ import { decryptResponse, encryptRequest } from '../encryption'
75
79
import { getCursorState } from '../utils'
76
80
import { focusAmazonQPanel } from './commands'
77
81
82
+ export function registerActiveEditorChangeListener ( languageClient : LanguageClient ) {
83
+ let debounceTimer : NodeJS . Timeout | undefined
84
+ vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
85
+ if ( debounceTimer ) {
86
+ clearTimeout ( debounceTimer )
87
+ }
88
+ debounceTimer = setTimeout ( ( ) => {
89
+ let textDocument = undefined
90
+ let cursorState = undefined
91
+ if ( editor ) {
92
+ textDocument = {
93
+ uri : editor . document . uri . toString ( ) ,
94
+ }
95
+ cursorState = getCursorState ( editor . selections )
96
+ }
97
+ languageClient . sendNotification ( activeEditorChangedNotificationType . method , {
98
+ textDocument,
99
+ cursorState,
100
+ } )
101
+ } , 100 )
102
+ } )
103
+ }
104
+
78
105
export function registerLanguageServerEventListener ( languageClient : LanguageClient , provider : AmazonQChatViewProvider ) {
79
106
languageClient . info (
80
107
'Language client received initializeResult from server:' ,
@@ -100,14 +127,6 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
100
127
const telemetryName : string = e . name
101
128
102
129
if ( telemetryName in telemetry ) {
103
- switch ( telemetryName ) {
104
- case 'codewhisperer_serviceInvocation' : {
105
- // this feature is entirely client side right now
106
- e . data . codewhispererImportRecommendationEnabled =
107
- CodeWhispererSettings . instance . isImportRecommendationEnabled ( )
108
- break
109
- }
110
- }
111
130
languageClient . info ( `[Telemetry] Emitting ${ telemetryName } telemetry: ${ JSON . stringify ( e . data ) } ` )
112
131
telemetry [ telemetryName as keyof TelemetryBase ] . emit ( e . data )
113
132
}
@@ -301,6 +320,8 @@ export function registerMessageListeners(
301
320
)
302
321
break
303
322
}
323
+ case listRulesRequestType . method :
324
+ case ruleClickRequestType . method :
304
325
case listConversationsRequestType . method :
305
326
case conversationClickRequestType . method :
306
327
case listMcpServersRequestType . method :
@@ -456,6 +477,20 @@ export function registerMessageListeners(
456
477
params : params ,
457
478
} )
458
479
} )
480
+ languageClient . onNotification (
481
+ pinnedContextNotificationType . method ,
482
+ ( params : ContextCommandParams & { tabId : string ; textDocument ?: TextDocumentIdentifier } ) => {
483
+ const editor = vscode . window . activeTextEditor
484
+ let textDocument = undefined
485
+ if ( editor && isTextEditor ( editor ) ) {
486
+ textDocument = { uri : vscode . workspace . asRelativePath ( editor . document . uri ) }
487
+ }
488
+ void provider . webview ?. postMessage ( {
489
+ command : pinnedContextNotificationType . method ,
490
+ params : { ...params , textDocument } ,
491
+ } )
492
+ }
493
+ )
459
494
460
495
languageClient . onNotification ( openFileDiffNotificationType . method , async ( params : OpenFileDiffParams ) => {
461
496
const ecc = new EditorContentController ( )
0 commit comments