@@ -15,12 +15,10 @@ import { LspClient } from './lspClient'
15
15
import AdmZip from 'adm-zip'
16
16
import { RelevantTextDocument } from '@amzn/codewhisperer-streaming'
17
17
import { makeTemporaryToolkitFolder , tryRemoveFolder } from '../../shared/filesystemUtilities'
18
- import { CodeWhispererSettings } from '../../codewhisperer/util/codewhispererSettings'
19
18
import { activate as activateLsp } from './lspClient'
20
19
import { telemetry } from '../../shared/telemetry'
21
20
import { isCloud9 } from '../../shared/extensionUtilities'
22
21
import { fs , globals , ToolkitError } from '../../shared'
23
- import { AuthUtil } from '../../codewhisperer'
24
22
import { isWeb } from '../../shared/extensionGlobals'
25
23
import { getUserAgent } from '../../shared/telemetry/util'
26
24
import { isAmazonInternalOs } from '../../shared/vscode/env'
@@ -68,9 +66,16 @@ export interface Manifest {
68
66
}
69
67
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
70
68
// this LSP client in Q extension is only going to work with these LSP server versions
71
- const supportedLspServerVersions = [ '0.1.13 ' ]
69
+ const supportedLspServerVersions = [ '0.1.22' , '0.1.19 ']
72
70
73
71
const nodeBinName = process . platform === 'win32' ? 'node.exe' : 'node'
72
+
73
+ export interface BuildIndexConfig {
74
+ startUrl ?: string
75
+ maxIndexSize : number
76
+ isVectorIndexEnabled : boolean
77
+ }
78
+
74
79
/*
75
80
* LSP Controller manages the status of Amazon Q LSP:
76
81
* 1. Downloading, verifying and installing LSP using DEXP LSP manifest and CDN.
@@ -281,7 +286,7 @@ export class LspController {
281
286
}
282
287
283
288
async query ( s : string ) : Promise < RelevantTextDocument [ ] > {
284
- const chunks : Chunk [ ] | undefined = await LspClient . instance . query ( s )
289
+ const chunks : Chunk [ ] | undefined = await LspClient . instance . queryVectorIndex ( s )
285
290
const resp : RelevantTextDocument [ ] = [ ]
286
291
chunks ?. forEach ( ( chunk ) => {
287
292
const text = chunk . context ? chunk . context : chunk . content
@@ -303,7 +308,15 @@ export class LspController {
303
308
return resp
304
309
}
305
310
306
- async buildIndex ( ) {
311
+ async queryInlineProjectContext ( query : string , path : string ) {
312
+ try {
313
+ return await LspClient . instance . queryInlineProjectContext ( query , path )
314
+ } catch ( e ) {
315
+ return [ ]
316
+ }
317
+ }
318
+
319
+ async buildIndex ( buildIndexConfig : BuildIndexConfig ) {
307
320
getLogger ( ) . info ( `LspController: Starting to build index of project` )
308
321
const start = performance . now ( )
309
322
const projPaths = getProjectPaths ( )
@@ -318,18 +331,16 @@ export class LspController {
318
331
projPaths ,
319
332
vscode . workspace . workspaceFolders as CurrentWsFolders ,
320
333
true ,
321
- CodeWhispererSettings . instance . getMaxIndexSize ( ) * 1024 * 1024
334
+ buildIndexConfig . maxIndexSize * 1024 * 1024
322
335
)
323
336
const totalSizeBytes = files . reduce (
324
337
( accumulator , currentFile ) => accumulator + currentFile . fileSizeBytes ,
325
338
0
326
339
)
327
340
getLogger ( ) . info ( `LspController: Found ${ files . length } files in current project ${ getProjectPaths ( ) } ` )
328
- const resp = await LspClient . instance . indexFiles (
329
- files . map ( ( f ) => f . fileUri . fsPath ) ,
330
- projRoot ,
331
- false
332
- )
341
+ const config = buildIndexConfig . isVectorIndexEnabled ? 'all' : 'default'
342
+ const r = files . map ( ( f ) => f . fileUri . fsPath )
343
+ const resp = await LspClient . instance . buildIndex ( r , projRoot , config )
333
344
if ( resp ) {
334
345
getLogger ( ) . debug ( `LspController: Finish building index of project` )
335
346
const usage = await LspClient . instance . getLspServerUsage ( )
@@ -340,31 +351,36 @@ export class LspController {
340
351
amazonqIndexMemoryUsageInMB : usage ? usage . memoryUsage / ( 1024 * 1024 ) : undefined ,
341
352
amazonqIndexCpuUsagePercentage : usage ? usage . cpuUsage : undefined ,
342
353
amazonqIndexFileSizeInMB : totalSizeBytes / ( 1024 * 1024 ) ,
343
- credentialStartUrl : AuthUtil . instance . startUrl ,
354
+ credentialStartUrl : buildIndexConfig . startUrl ,
344
355
} )
345
356
} else {
346
- getLogger ( ) . error ( `LspController: Failed to build index of project` )
347
- telemetry . amazonq_indexWorkspace . emit ( {
348
- duration : performance . now ( ) - start ,
349
- result : 'Failed' ,
350
- amazonqIndexFileCount : 0 ,
351
- amazonqIndexFileSizeInMB : 0 ,
352
- } )
357
+ // TODO: Re-enable this code path for LSP 0.1.20+
358
+ // getLogger().error(`LspController: Failed to build index of project`)
359
+ // telemetry.amazonq_indexWorkspace.emit({
360
+ // duration: performance.now() - start,
361
+ // result: 'Failed',
362
+ // amazonqIndexFileCount: 0,
363
+ // amazonqIndexFileSizeInMB: 0,
364
+ // reason: `Unknown`,
365
+ // })
353
366
}
354
- } catch ( e ) {
367
+ } catch ( error ) {
368
+ //TODO: use telemetry.run()
355
369
getLogger ( ) . error ( `LspController: Failed to build index of project` )
356
370
telemetry . amazonq_indexWorkspace . emit ( {
357
371
duration : performance . now ( ) - start ,
358
372
result : 'Failed' ,
359
373
amazonqIndexFileCount : 0 ,
360
374
amazonqIndexFileSizeInMB : 0 ,
375
+ reason : `${ error instanceof Error ? error . name : 'Unknown' } ` ,
376
+ reasonDesc : `Error when building index. ${ error instanceof Error ? error . message : error } ` ,
361
377
} )
362
378
} finally {
363
379
this . _isIndexingInProgress = false
364
380
}
365
381
}
366
382
367
- async trySetupLsp ( context : vscode . ExtensionContext ) {
383
+ async trySetupLsp ( context : vscode . ExtensionContext , buildIndexConfig : BuildIndexConfig ) {
368
384
if ( isCloud9 ( ) || isWeb ( ) || isAmazonInternalOs ( ) ) {
369
385
getLogger ( ) . warn ( 'LspController: Skipping LSP setup. LSP is not compatible with the current environment. ' )
370
386
// do not do anything if in Cloud9 or Web mode or in AL2 (AL2 does not support node v18+)
@@ -378,9 +394,7 @@ export class LspController {
378
394
try {
379
395
await activateLsp ( context )
380
396
getLogger ( ) . info ( 'LspController: LSP activated' )
381
- if ( CodeWhispererSettings . instance . isLocalIndexEnabled ( ) ) {
382
- void LspController . instance . buildIndex ( )
383
- }
397
+ void LspController . instance . buildIndex ( buildIndexConfig )
384
398
// log the LSP server CPU and Memory usage per 30 minutes.
385
399
globals . clock . setInterval (
386
400
async ( ) => {
0 commit comments