@@ -15,12 +15,10 @@ import { LspClient } from './lspClient'
1515import AdmZip from 'adm-zip'
1616import { RelevantTextDocument } from '@amzn/codewhisperer-streaming'
1717import { makeTemporaryToolkitFolder , tryRemoveFolder } from '../../shared/filesystemUtilities'
18- import { CodeWhispererSettings } from '../../codewhisperer/util/codewhispererSettings'
1918import { activate as activateLsp } from './lspClient'
2019import { telemetry } from '../../shared/telemetry'
2120import { isCloud9 } from '../../shared/extensionUtilities'
2221import { fs , globals , ToolkitError } from '../../shared'
23- import { AuthUtil } from '../../codewhisperer'
2422import { isWeb } from '../../shared/extensionGlobals'
2523import { getUserAgent } from '../../shared/telemetry/util'
2624import { isAmazonInternalOs } from '../../shared/vscode/env'
@@ -68,9 +66,16 @@ export interface Manifest {
6866}
6967const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
7068// 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 ']
7270
7371const nodeBinName = process . platform === 'win32' ? 'node.exe' : 'node'
72+
73+ export interface BuildIndexConfig {
74+ startUrl ?: string
75+ maxIndexSize : number
76+ isVectorIndexEnabled : boolean
77+ }
78+
7479/*
7580 * LSP Controller manages the status of Amazon Q LSP:
7681 * 1. Downloading, verifying and installing LSP using DEXP LSP manifest and CDN.
@@ -281,7 +286,7 @@ export class LspController {
281286 }
282287
283288 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 )
285290 const resp : RelevantTextDocument [ ] = [ ]
286291 chunks ?. forEach ( ( chunk ) => {
287292 const text = chunk . context ? chunk . context : chunk . content
@@ -303,7 +308,15 @@ export class LspController {
303308 return resp
304309 }
305310
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 ) {
307320 getLogger ( ) . info ( `LspController: Starting to build index of project` )
308321 const start = performance . now ( )
309322 const projPaths = getProjectPaths ( )
@@ -318,18 +331,16 @@ export class LspController {
318331 projPaths ,
319332 vscode . workspace . workspaceFolders as CurrentWsFolders ,
320333 true ,
321- CodeWhispererSettings . instance . getMaxIndexSize ( ) * 1024 * 1024
334+ buildIndexConfig . maxIndexSize * 1024 * 1024
322335 )
323336 const totalSizeBytes = files . reduce (
324337 ( accumulator , currentFile ) => accumulator + currentFile . fileSizeBytes ,
325338 0
326339 )
327340 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 )
333344 if ( resp ) {
334345 getLogger ( ) . debug ( `LspController: Finish building index of project` )
335346 const usage = await LspClient . instance . getLspServerUsage ( )
@@ -340,31 +351,36 @@ export class LspController {
340351 amazonqIndexMemoryUsageInMB : usage ? usage . memoryUsage / ( 1024 * 1024 ) : undefined ,
341352 amazonqIndexCpuUsagePercentage : usage ? usage . cpuUsage : undefined ,
342353 amazonqIndexFileSizeInMB : totalSizeBytes / ( 1024 * 1024 ) ,
343- credentialStartUrl : AuthUtil . instance . startUrl ,
354+ credentialStartUrl : buildIndexConfig . startUrl ,
344355 } )
345356 } 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+ // })
353366 }
354- } catch ( e ) {
367+ } catch ( error ) {
368+ //TODO: use telemetry.run()
355369 getLogger ( ) . error ( `LspController: Failed to build index of project` )
356370 telemetry . amazonq_indexWorkspace . emit ( {
357371 duration : performance . now ( ) - start ,
358372 result : 'Failed' ,
359373 amazonqIndexFileCount : 0 ,
360374 amazonqIndexFileSizeInMB : 0 ,
375+ reason : `${ error instanceof Error ? error . name : 'Unknown' } ` ,
376+ reasonDesc : `Error when building index. ${ error instanceof Error ? error . message : error } ` ,
361377 } )
362378 } finally {
363379 this . _isIndexingInProgress = false
364380 }
365381 }
366382
367- async trySetupLsp ( context : vscode . ExtensionContext ) {
383+ async trySetupLsp ( context : vscode . ExtensionContext , buildIndexConfig : BuildIndexConfig ) {
368384 if ( isCloud9 ( ) || isWeb ( ) || isAmazonInternalOs ( ) ) {
369385 getLogger ( ) . warn ( 'LspController: Skipping LSP setup. LSP is not compatible with the current environment. ' )
370386 // 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 {
378394 try {
379395 await activateLsp ( context )
380396 getLogger ( ) . info ( 'LspController: LSP activated' )
381- if ( CodeWhispererSettings . instance . isLocalIndexEnabled ( ) ) {
382- void LspController . instance . buildIndex ( )
383- }
397+ void LspController . instance . buildIndex ( buildIndexConfig )
384398 // log the LSP server CPU and Memory usage per 30 minutes.
385399 globals . clock . setInterval (
386400 async ( ) => {
0 commit comments