@@ -15,6 +15,7 @@ import { isAmazonInternalOs } from '../../shared/vscode/env'
1515import { WorkspaceLspInstaller } from './workspaceInstaller'
1616import { lspSetupStage } from '../../shared/lsp/utils/setupStage'
1717import { RelevantTextDocumentAddition } from '../../codewhispererChat/controllers/chat/model'
18+ import { waitUntil } from '../../shared/utilities/timeoutUtils'
1819
1920export interface Chunk {
2021 readonly filePath : string
@@ -45,6 +46,7 @@ export interface BuildIndexConfig {
4546export class LspController {
4647 static #instance: LspController
4748 private _isIndexingInProgress = false
49+ private _contextCommandSymbolsUpdated = false
4850 private logger = getLogger ( 'amazonqWorkspaceLsp' )
4951
5052 public static get instance ( ) {
@@ -192,6 +194,38 @@ export class LspController {
192194 }
193195 } )
194196 }
197+ /**
198+ * Updates context command symbols once per session by synchronizing with the LSP client index.
199+ * Context menu will contain file and folders to begin with,
200+ * then this asynchronous function should be invoked after the files and folders are found
201+ * the LSP then further starts to parse workspace and find symbols, which takes
202+ * anywhere from 5 seconds to about 40 seconds, depending on project size.
203+ * @returns {Promise<void> }
204+ */
205+ async updateContextCommandSymbolsOnce ( ) {
206+ if ( this . _contextCommandSymbolsUpdated ) {
207+ return
208+ }
209+ this . _contextCommandSymbolsUpdated = true
210+ getLogger ( ) . debug ( `LspController: Start adding symbols to context picker menu` )
211+ try {
212+ const indexSeqNum = await LspClient . instance . getIndexSequenceNumber ( )
213+ await LspClient . instance . updateIndex ( [ ] , 'context_command_symbol_update' )
214+ await waitUntil (
215+ async ( ) => {
216+ const newIndexSeqNum = await LspClient . instance . getIndexSequenceNumber ( )
217+ if ( newIndexSeqNum > indexSeqNum ) {
218+ await vscode . commands . executeCommand ( `aws.amazonq.updateContextCommandItems` )
219+ return true
220+ }
221+ return false
222+ } ,
223+ { interval : 1000 , timeout : 60_000 , truthy : true }
224+ )
225+ } catch ( err ) {
226+ getLogger ( ) . error ( `LspController: Failed to find symbols` )
227+ }
228+ }
195229
196230 private async setupLsp ( context : vscode . ExtensionContext ) {
197231 await lspSetupStage ( 'all' , async ( ) => {
0 commit comments