@@ -33,7 +33,6 @@ import {
3333import { Writable } from 'stream'
3434import { CodeWhispererSettings } from '../../codewhisperer/util/codewhispererSettings'
3535import { ResourcePaths , fs , getLogger , globals } from '../../shared'
36- import { telemetry } from '../../shared/telemetry'
3736
3837const localize = nls . loadMessageBundle ( )
3938
@@ -174,108 +173,103 @@ export class LspClient {
174173 * This function assumes the LSP server has already been downloaded.
175174 */
176175export async function activate ( extensionContext : ExtensionContext , resourcePaths : ResourcePaths ) {
177- return await telemetry . languageServer_setup . run ( async ( span ) => {
178- span . record ( { languageServerSetupStage : 'launch' } )
179- const startTime = performance . now ( )
180- LspClient . instance
181- const toDispose = extensionContext . subscriptions
176+ LspClient . instance
177+ const toDispose = extensionContext . subscriptions
182178
183- let rangeFormatting : Disposable | undefined
184- // The debug options for the server
185- // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
186- const debugOptions = { execArgv : [ '--nolazy' , '--preserve-symlinks' , '--stdio' ] }
179+ let rangeFormatting : Disposable | undefined
180+ // The debug options for the server
181+ // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
182+ const debugOptions = { execArgv : [ '--nolazy' , '--preserve-symlinks' , '--stdio' ] }
187183
188- const workerThreads = CodeWhispererSettings . instance . getIndexWorkerThreads ( )
189- const gpu = CodeWhispererSettings . instance . isLocalIndexGPUEnabled ( )
184+ const workerThreads = CodeWhispererSettings . instance . getIndexWorkerThreads ( )
185+ const gpu = CodeWhispererSettings . instance . isLocalIndexGPUEnabled ( )
190186
191- if ( gpu ) {
192- process . env . Q_ENABLE_GPU = 'true'
193- } else {
194- delete process . env . Q_ENABLE_GPU
195- }
196- if ( workerThreads > 0 && workerThreads < 100 ) {
197- process . env . Q_WORKER_THREADS = workerThreads . toString ( )
198- } else {
199- delete process . env . Q_WORKER_THREADS
200- }
187+ if ( gpu ) {
188+ process . env . Q_ENABLE_GPU = 'true'
189+ } else {
190+ delete process . env . Q_ENABLE_GPU
191+ }
192+ if ( workerThreads > 0 && workerThreads < 100 ) {
193+ process . env . Q_WORKER_THREADS = workerThreads . toString ( )
194+ } else {
195+ delete process . env . Q_WORKER_THREADS
196+ }
201197
202- const serverModule = resourcePaths . lsp
198+ const serverModule = resourcePaths . lsp
203199
204- const child = spawn ( resourcePaths . node , [ serverModule , ...debugOptions . execArgv ] )
205- // share an encryption key using stdin
206- // follow same practice of DEXP LSP server
207- writeEncryptionInit ( child . stdin )
200+ const child = spawn ( resourcePaths . node , [ serverModule , ...debugOptions . execArgv ] )
201+ // share an encryption key using stdin
202+ // follow same practice of DEXP LSP server
203+ writeEncryptionInit ( child . stdin )
208204
209- // If the extension is launch in debug mode the debug server options are use
210- // Otherwise the run options are used
211- let serverOptions : ServerOptions = {
212- run : { module : serverModule , transport : TransportKind . ipc } ,
213- debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } ,
214- }
205+ // If the extension is launch in debug mode the debug server options are use
206+ // Otherwise the run options are used
207+ let serverOptions : ServerOptions = {
208+ run : { module : serverModule , transport : TransportKind . ipc } ,
209+ debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } ,
210+ }
215211
216- serverOptions = ( ) => Promise . resolve ( child ! )
212+ serverOptions = ( ) => Promise . resolve ( child ! )
217213
218- const documentSelector = [ { scheme : 'file' , language : '*' } ]
214+ const documentSelector = [ { scheme : 'file' , language : '*' } ]
219215
220- // Options to control the language client
221- const clientOptions : LanguageClientOptions = {
222- // Register the server for json documents
223- documentSelector,
224- initializationOptions : {
225- handledSchemaProtocols : [ 'file' , 'untitled' ] , // language server only loads file-URI. Fetching schemas with other protocols ('http'...) are made on the client.
226- provideFormatter : false , // tell the server to not provide formatting capability and ignore the `aws.stepfunctions.asl.format.enable` setting.
227- // this is used by LSP to determine index cache path, move to this folder so that when extension updates index is not deleted.
228- extensionPath : path . join ( fs . getUserHomeDir ( ) , '.aws' , 'amazonq' , 'cache' ) ,
229- } ,
230- // Log to the Amazon Q Logs so everything is in a single channel
231- // TODO: Add prefix to the language server logs so it is easier to search
232- outputChannel : globals . logOutputChannel ,
233- }
216+ // Options to control the language client
217+ const clientOptions : LanguageClientOptions = {
218+ // Register the server for json documents
219+ documentSelector,
220+ initializationOptions : {
221+ handledSchemaProtocols : [ 'file' , 'untitled' ] , // language server only loads file-URI. Fetching schemas with other protocols ('http'...) are made on the client.
222+ provideFormatter : false , // tell the server to not provide formatting capability and ignore the `aws.stepfunctions.asl.format.enable` setting.
223+ // this is used by LSP to determine index cache path, move to this folder so that when extension updates index is not deleted.
224+ extensionPath : path . join ( fs . getUserHomeDir ( ) , '.aws' , 'amazonq' , 'cache' ) ,
225+ } ,
226+ // Log to the Amazon Q Logs so everything is in a single channel
227+ // TODO: Add prefix to the language server logs so it is easier to search
228+ outputChannel : globals . logOutputChannel ,
229+ }
234230
235- // Create the language client and start the client.
236- LspClient . instance . client = new LanguageClient (
237- 'amazonq' ,
238- localize ( 'amazonq.server.name' , 'Amazon Q Language Server' ) ,
239- serverOptions ,
240- clientOptions
241- )
242- LspClient . instance . client . registerProposedFeatures ( )
231+ // Create the language client and start the client.
232+ LspClient . instance . client = new LanguageClient (
233+ 'amazonq' ,
234+ localize ( 'amazonq.server.name' , 'Amazon Q Language Server' ) ,
235+ serverOptions ,
236+ clientOptions
237+ )
238+ LspClient . instance . client . registerProposedFeatures ( )
243239
244- const disposable = LspClient . instance . client . start ( )
245- toDispose . push ( disposable )
240+ const disposable = LspClient . instance . client . start ( )
241+ toDispose . push ( disposable )
246242
247- let savedDocument : vscode . Uri | undefined = undefined
243+ let savedDocument : vscode . Uri | undefined = undefined
248244
249- toDispose . push (
250- vscode . workspace . onDidSaveTextDocument ( ( document ) => {
251- if ( document . uri . scheme !== 'file' ) {
252- return
253- }
254- savedDocument = document . uri
255- } ) ,
256- vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
257- if ( savedDocument && editor && editor . document . uri . fsPath !== savedDocument . fsPath ) {
258- void LspClient . instance . updateIndex ( [ savedDocument . fsPath ] , 'update' )
259- }
260- } ) ,
261- vscode . workspace . onDidCreateFiles ( ( e ) => {
262- void LspClient . instance . updateIndex (
263- e . files . map ( ( f ) => f . fsPath ) ,
264- 'add'
265- )
266- } ) ,
267- vscode . workspace . onDidDeleteFiles ( ( e ) => {
268- void LspClient . instance . updateIndex (
269- e . files . map ( ( f ) => f . fsPath ) ,
270- 'remove'
271- )
272- } )
273- )
274- void LspClient . instance . client . onReady ( ) . then ( ( ) => {
275- const disposableFunc = { dispose : ( ) => rangeFormatting ?. dispose ( ) as void }
276- toDispose . push ( disposableFunc )
245+ toDispose . push (
246+ vscode . workspace . onDidSaveTextDocument ( ( document ) => {
247+ if ( document . uri . scheme !== 'file' ) {
248+ return
249+ }
250+ savedDocument = document . uri
251+ } ) ,
252+ vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
253+ if ( savedDocument && editor && editor . document . uri . fsPath !== savedDocument . fsPath ) {
254+ void LspClient . instance . updateIndex ( [ savedDocument . fsPath ] , 'update' )
255+ }
256+ } ) ,
257+ vscode . workspace . onDidCreateFiles ( ( e ) => {
258+ void LspClient . instance . updateIndex (
259+ e . files . map ( ( f ) => f . fsPath ) ,
260+ 'add'
261+ )
262+ } ) ,
263+ vscode . workspace . onDidDeleteFiles ( ( e ) => {
264+ void LspClient . instance . updateIndex (
265+ e . files . map ( ( f ) => f . fsPath ) ,
266+ 'remove'
267+ )
277268 } )
278- span . record ( { duration : performance . now ( ) - startTime } )
269+ )
270+ void LspClient . instance . client . onReady ( ) . then ( ( ) => {
271+ const disposableFunc = { dispose : ( ) => rangeFormatting ?. dispose ( ) as void }
272+ toDispose . push ( disposableFunc )
279273 } )
280274}
281275
0 commit comments