Skip to content

Commit 4d1b0bb

Browse files
authored
fix(amazonq): skip indexing when no workspace folders are found (aws#6058)
## Problem If customers open a workspace without a workspace folder they get: ``` 2024-11-19 10:49:16.189 [error] Error: No workspace folders found at k (/Users/myuser/.vscode/extensions/amazonwebservices.amazon-q-vscode-99.0.0-g3afd54d/dist/src/extensionNode.js:5464:5562) at L.buildIndex (/Users/myuser/.vscode/extensions/amazonwebservices.amazon-q-vscode-99.0.0-g3afd54d/dist/src/extensionNode.js:5464:9890) at Immediate.<anonymous> (/Users/myuser/.vscode/extensions/amazonwebservices.amazon-q-vscode-99.0.0-g3afd54d/dist/src/extensionNode.js:5464:11854) ``` because workspace indexing is throwing an error ## Solution Log that no workspace folders were found so indexing is skipped
1 parent c6c5fc2 commit 4d1b0bb

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "amazon q inline: skip indexing when no workspace folders are found"
4+
}

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ import { isWeb } from '../../shared/extensionGlobals'
2323
import { getUserAgent } from '../../shared/telemetry/util'
2424
import { isAmazonInternalOs } from '../../shared/vscode/env'
2525

26-
function getProjectPaths() {
27-
const workspaceFolders = vscode.workspace.workspaceFolders
28-
if (!workspaceFolders || workspaceFolders.length === 0) {
29-
throw new ToolkitError('No workspace folders found')
30-
}
31-
return workspaceFolders.map((folder) => folder.uri.fsPath)
32-
}
33-
3426
export interface Chunk {
3527
readonly filePath: string
3628
readonly content: string
@@ -322,12 +314,13 @@ export class LspController {
322314
async buildIndex(buildIndexConfig: BuildIndexConfig) {
323315
getLogger().info(`LspController: Starting to build index of project`)
324316
const start = performance.now()
325-
const projPaths = getProjectPaths()
317+
const projPaths = (vscode.workspace.workspaceFolders ?? []).map((folder) => folder.uri.fsPath)
318+
if (projPaths.length === 0) {
319+
getLogger().info(`LspController: Skipping building index. No projects found in workspace`)
320+
return
321+
}
326322
projPaths.sort()
327323
try {
328-
if (projPaths.length === 0) {
329-
throw Error('No project')
330-
}
331324
this._isIndexingInProgress = true
332325
const projRoot = projPaths[0]
333326
const files = await collectFilesForIndex(
@@ -340,7 +333,7 @@ export class LspController {
340333
(accumulator, currentFile) => accumulator + currentFile.fileSizeBytes,
341334
0
342335
)
343-
getLogger().info(`LspController: Found ${files.length} files in current project ${getProjectPaths()}`)
336+
getLogger().info(`LspController: Found ${files.length} files in current project ${projPaths}`)
344337
const config = buildIndexConfig.isVectorIndexEnabled ? 'all' : 'default'
345338
const r = files.map((f) => f.fileUri.fsPath)
346339
const resp = await LspClient.instance.buildIndex(r, projRoot, config)

0 commit comments

Comments
 (0)