Skip to content

Commit 8263207

Browse files
angelozerrdatho7561
authored andcommitted
XML support crashes when workspace folders are empty
Fixes #940 Signed-off-by: azerr <[email protected]>
1 parent 0e87aa6 commit 8263207

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/utils/fileUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TextDocument, Uri, workspace, WorkspaceFolder } from "vscode";
99
*/
1010
export function getWorkspaceUri(document: TextDocument): Uri | undefined {
1111
const currentWorkspace: WorkspaceFolder = (document && document.uri) ? workspace.getWorkspaceFolder(document.uri) : undefined;
12-
return ((currentWorkspace && currentWorkspace.uri) || (workspace.workspaceFolders && workspace.workspaceFolders[0].uri));
12+
return ((currentWorkspace && currentWorkspace.uri) || (workspace.workspaceFolders && workspace.workspaceFolders.length > 0 && workspace.workspaceFolders[0].uri));
1313
}
1414

1515
/**
@@ -52,4 +52,4 @@ export function getRelativePath(startPath: string, destinationPath: string): str
5252
export function getDirectoryPath(filePath: string): string {
5353
return path.dirname(filePath);
5454

55-
}
55+
}

0 commit comments

Comments
 (0)