Skip to content

Commit

Permalink
Handle multi-root workspace variable - issue ChrisChinchilla#10
Browse files Browse the repository at this point in the history
  • Loading branch information
hangie committed Apr 4, 2024
1 parent 419abe7 commit 220ed1a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/features/vsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ function replaceWorkspaceFolder(
file: vscode.TextDocument
): string | null {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(file.uri);

// Handle mutli-root workspace scenarios.
if (vscode.workspace.workspaceFolders) {
let replaced = false;
vscode.workspace.workspaceFolders.some(function (value, index, array) {
let searchStr = `\${workspaceFolder:${value.name}}`;
if (customPath.startsWith(searchStr)) {
// Handle workspace folder ${workspaceFolder:NAME} scenario
let newPath = customPath.replace(searchStr, value.uri.fsPath);
customPath = path.normalize(newPath);
replaced = true;
return true;
}
return false;
});
if (replaced) {
return customPath;
}
}
if (workspaceFolder) {
customPath = customPath.replace("${workspaceFolder}", workspaceFolder.uri.fsPath);
customPath = path.normalize(customPath);
Expand Down

0 comments on commit 220ed1a

Please sign in to comment.