Skip to content

Commit a165d58

Browse files
Merge pull request #694 from intersystems-community/fix-693
fix #693 handle startup case where current file is not in any root of the workspace
2 parents 322fdf9 + 6e5de9c commit a165d58

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/utils/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ export function isCSP(uri: vscode.Uri): boolean {
259259
export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
260260
document = document ? document : vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
261261
if (document) {
262-
return workspaceFolderOfUri(document.uri);
262+
const folder = workspaceFolderOfUri(document.uri);
263+
// document might not be part of the workspace (e.g. the XXX.code-workspace JSON file)
264+
if (folder) {
265+
return folder;
266+
}
263267
}
264268
const firstFolder =
265269
vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length
@@ -284,6 +288,7 @@ export function workspaceFolderOfUri(uri: vscode.Uri): string {
284288
);
285289
return foundFolder ? foundFolder.name : uri.authority;
286290
}
291+
return "";
287292
}
288293

289294
export function uriOfWorkspaceFolder(workspaceFolder: string = currentWorkspaceFolder()): vscode.Uri {

0 commit comments

Comments
 (0)