Skip to content

Commit f45e95c

Browse files
committed
Handle no workspace being open
1 parent 4edbd9a commit f45e95c

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
- Fixed an error in document symbol provider when viewing a file located outside of current workspace.
6+
- Fixed an error in workspace symbol provider when no workspace is open.
7+
38
## 2025.9.0
49

510
- Added "Rebuild Ctags" editor Command. The old method of building ctags via a Task is going to be deprecated.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"functions": 90,
8989
"lines": 90
9090
}
91-
}
91+
},
92+
"restoreMocks": true
9293
}
9394
}

src/readtags.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class ReadtagsProvider {
3939
*/
4040
async provideWorkspaceSymbols(query) {
4141
if (!query) return [];
42+
// if (vscode.workspace.workspaceFolders === undefined) return [];
4243

43-
// TODO FIXME handle vscode.workspace.workspaceFolders being undefined when no workspace folder is open
44-
// @ts-expect-error
4544
const results = await Promise.all(vscode.workspace.workspaceFolders.map(async scope => {
4645
const command = getConfiguration(scope).get("readtagsGoToSymbolInWorkspaceCommand");
4746
const cwd = scope.uri.fsPath;

src/readtags.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ describe(ReadtagsProvider, () => {
7777
const definitions = await provider.provideWorkspaceSymbols("foobar");
7878
expect(definitions).toEqual([]);
7979
});
80+
81+
it("returns an empty list when no workspace is open", async () => {
82+
jest.replaceProperty(vscode.workspace, 'workspaceFolders', undefined);
83+
const provider = new ReadtagsProvider(undefined);
84+
const definitions = await provider.provideWorkspaceSymbols("foobar");
85+
expect(definitions).toEqual([]);
86+
});
8087
});
8188

8289
describe("provideDocumentSymbols", () => {

0 commit comments

Comments
 (0)