Skip to content

Commit

Permalink
Cleaned up getWorkspaceFolder (DH-18163)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Dec 20, 2024
1 parent 67a2d3e commit f8f7a33
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/util/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,20 @@ export async function getEditorForUri(
* @returns The workspace folder or undefined if there are no workspace folders.
*/
export function getWorkspaceFolder(): vscode.WorkspaceFolder | undefined {
const wkspFolders = vscode.workspace.workspaceFolders ?? [];

if (wkspFolders.length === 0) {
return;
}

const activeUri = vscode.window.activeTextEditor?.document.uri;

// For multi-root workspaces, attempt to derive the workspace folder based
// on active editor
const wkspFolder =
const activeWkspFolder =
activeUri == null
? null
: vscode.workspace.workspaceFolders?.find(path =>
activeUri?.fsPath.startsWith(path.uri.fsPath)
);
: wkspFolders.find(path => activeUri.fsPath.startsWith(path.uri.fsPath));

// Fallback to first workspace folder
return wkspFolder ?? vscode.workspace.workspaceFolders?.[0];
return activeWkspFolder ?? wkspFolders[0];
}

/**
Expand Down

0 comments on commit f8f7a33

Please sign in to comment.