66import vscode , { env , version } from 'vscode'
77import * as nls from 'vscode-nls'
88import * as crypto from 'crypto'
9- import { LanguageClient , LanguageClientOptions } from 'vscode-languageclient'
9+ import { LanguageClient , LanguageClientOptions , RequestType } from 'vscode-languageclient'
1010import { InlineCompletionManager } from '../app/inline/completion'
1111import { AmazonQLspAuth , encryptionKey , notificationTypes } from './auth'
1212import { AuthUtil } from 'aws-core-vscode/codewhisperer'
13- import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
13+ import {
14+ ConnectionMetadata ,
15+ CreateFilesParams ,
16+ DeleteFilesParams ,
17+ DidChangeWorkspaceFoldersParams ,
18+ DidSaveTextDocumentParams ,
19+ GetConfigurationFromServerParams ,
20+ RenameFilesParams ,
21+ ResponseMessage ,
22+ updateConfigurationRequestType ,
23+ WorkspaceFolder ,
24+ } from '@aws/language-server-runtimes/protocol'
1425import {
1526 Settings ,
1627 oidcClientName ,
1728 createServerOptions ,
1829 globals ,
1930 Experiments ,
2031 Commands ,
32+ oneSecond ,
2133 validateNodeExe ,
2234 getLogger ,
2335} from 'aws-core-vscode/shared'
@@ -75,6 +87,9 @@ export async function startLanguageServer(
7587 window : {
7688 notifications : true ,
7789 } ,
90+ q : {
91+ developerProfiles : true ,
92+ } ,
7893 } ,
7994 } ,
8095 credentials : {
@@ -134,7 +149,27 @@ export async function startLanguageServer(
134149 activate ( client , encryptionKey , resourcePaths . ui )
135150 }
136151
137- const refreshInterval = auth . startTokenRefreshInterval ( )
152+ const refreshInterval = auth . startTokenRefreshInterval ( 10 * oneSecond )
153+
154+ const sendProfileToLsp = async ( ) => {
155+ try {
156+ const result = await client . sendRequest ( updateConfigurationRequestType . method , {
157+ section : 'aws.q' ,
158+ settings : {
159+ profileArn : AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn ,
160+ } ,
161+ } )
162+ client . info (
163+ `Client: Updated Amazon Q Profile ${ AuthUtil . instance . regionProfileManager . activeRegionProfile ?. arn } to Amazon Q LSP` ,
164+ result
165+ )
166+ } catch ( err ) {
167+ client . error ( 'Error when setting Q Developer Profile to Amazon Q LSP' , err )
168+ }
169+ }
170+
171+ // send profile to lsp once.
172+ void sendProfileToLsp ( )
138173
139174 toDispose . push (
140175 AuthUtil . instance . auth . onDidChangeActiveConnection ( async ( ) => {
@@ -143,6 +178,62 @@ export async function startLanguageServer(
143178 AuthUtil . instance . auth . onDidDeleteConnection ( async ( ) => {
144179 client . sendNotification ( notificationTypes . deleteBearerToken . method )
145180 } ) ,
181+ AuthUtil . instance . regionProfileManager . onDidChangeRegionProfile ( sendProfileToLsp ) ,
182+ vscode . commands . registerCommand ( 'aws.amazonq.getWorkspaceId' , async ( ) => {
183+ const requestType = new RequestType < GetConfigurationFromServerParams , ResponseMessage , Error > (
184+ 'aws/getConfigurationFromServer'
185+ )
186+ const workspaceIdResp = await client . sendRequest ( requestType . method , {
187+ section : 'aws.q.workspaceContext' ,
188+ } )
189+ return workspaceIdResp
190+ } ) ,
191+ vscode . workspace . onDidCreateFiles ( ( e ) => {
192+ client . sendNotification ( 'workspace/didCreateFiles' , {
193+ files : e . files . map ( ( it ) => {
194+ return { uri : it . fsPath }
195+ } ) ,
196+ } as CreateFilesParams )
197+ } ) ,
198+ vscode . workspace . onDidDeleteFiles ( ( e ) => {
199+ client . sendNotification ( 'workspace/didDeleteFiles' , {
200+ files : e . files . map ( ( it ) => {
201+ return { uri : it . fsPath }
202+ } ) ,
203+ } as DeleteFilesParams )
204+ } ) ,
205+ vscode . workspace . onDidRenameFiles ( ( e ) => {
206+ client . sendNotification ( 'workspace/didRenameFiles' , {
207+ files : e . files . map ( ( it ) => {
208+ return { oldUri : it . oldUri . fsPath , newUri : it . newUri . fsPath }
209+ } ) ,
210+ } as RenameFilesParams )
211+ } ) ,
212+ vscode . workspace . onDidSaveTextDocument ( ( e ) => {
213+ client . sendNotification ( 'workspace/didSaveTextDocument' , {
214+ textDocument : {
215+ uri : e . uri . fsPath ,
216+ } ,
217+ } as DidSaveTextDocumentParams )
218+ } ) ,
219+ vscode . workspace . onDidChangeWorkspaceFolders ( ( e ) => {
220+ client . sendNotification ( 'workspace/didChangeWorkspaceFolder' , {
221+ event : {
222+ added : e . added . map ( ( it ) => {
223+ return {
224+ name : it . name ,
225+ uri : it . uri . fsPath ,
226+ } as WorkspaceFolder
227+ } ) ,
228+ removed : e . removed . map ( ( it ) => {
229+ return {
230+ name : it . name ,
231+ uri : it . uri . fsPath ,
232+ } as WorkspaceFolder
233+ } ) ,
234+ } ,
235+ } as DidChangeWorkspaceFoldersParams )
236+ } ) ,
146237 { dispose : ( ) => clearInterval ( refreshInterval ) }
147238 )
148239 } )
0 commit comments