6
6
import vscode , { env , version } from 'vscode'
7
7
import * as nls from 'vscode-nls'
8
8
import * as crypto from 'crypto'
9
- import { LanguageClient , LanguageClientOptions } from 'vscode-languageclient'
9
+ import { LanguageClient , LanguageClientOptions , RequestType } from 'vscode-languageclient'
10
10
import { InlineCompletionManager } from '../app/inline/completion'
11
11
import { AmazonQLspAuth , encryptionKey , notificationTypes } from './auth'
12
12
import { 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'
14
25
import {
15
26
Settings ,
16
27
oidcClientName ,
17
28
createServerOptions ,
18
29
globals ,
19
30
Experiments ,
20
31
Commands ,
32
+ oneSecond ,
21
33
validateNodeExe ,
22
34
getLogger ,
23
35
} from 'aws-core-vscode/shared'
@@ -75,6 +87,9 @@ export async function startLanguageServer(
75
87
window : {
76
88
notifications : true ,
77
89
} ,
90
+ q : {
91
+ developerProfiles : true ,
92
+ } ,
78
93
} ,
79
94
} ,
80
95
credentials : {
@@ -134,7 +149,27 @@ export async function startLanguageServer(
134
149
activate ( client , encryptionKey , resourcePaths . ui )
135
150
}
136
151
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 ( )
138
173
139
174
toDispose . push (
140
175
AuthUtil . instance . auth . onDidChangeActiveConnection ( async ( ) => {
@@ -143,6 +178,62 @@ export async function startLanguageServer(
143
178
AuthUtil . instance . auth . onDidDeleteConnection ( async ( ) => {
144
179
client . sendNotification ( notificationTypes . deleteBearerToken . method )
145
180
} ) ,
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
+ } ) ,
146
237
{ dispose : ( ) => clearInterval ( refreshInterval ) }
147
238
)
148
239
} )
0 commit comments