Skip to content

Commit

Permalink
Turns out NodeJS path normalization is enough on its own
Browse files Browse the repository at this point in the history
  • Loading branch information
sam20908 committed Dec 7, 2024
1 parent e785459 commit dfa6072
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Provide run settings for the languages you use in `settings.json`. Here are some
We can use the following variables in the syntax of `${...}`
- Most of [VSCode's built-in variables](https://code.visualstudio.com/docs/editor/variables-reference)
- `${exeExtname}` returns `.exe` for Windows and an empty string for other platforms
- `${path:*some value*}` turns \*some value\* into a valid path string for the current platform, which normalizes slashes and handles spaces
- `${path:*value*}` normalizes \*value\* into a valid path string for the current platform

<details>
<summary>Possible settings per language</summary>
Expand Down
6 changes: 1 addition & 5 deletions src/extension/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ async function replaceAsync(string: string, regexp: RegExp, replacer: Function)
return string.replace(regexp, () => replacements[i++]);
}

function normalizePath(str: string) {
return path.normalize(os.platform() === 'win32' ? `"${str}"` : str.replace(/ /g, '\ '));
}

export interface ILanguageRunSettings {
compileCommand?: string;
runCommand: string;
Expand Down Expand Up @@ -232,7 +228,7 @@ export async function resolveVariables(string: string, recursive: boolean = fals
string = string.replace(/\${env:(.*?)}/g, match => process.env[match] ?? '');
string = string.replace(/\${config:(.*?)}/g, match => vscode.workspace.getConfiguration().get(match) ?? '');
string = string.replace(/\${exeExtname}/, os.platform() === 'win32' ? '.exe' : '');
string = await replaceAsync(string, /\${path:(.*?)}/g, async (match: string) => normalizePath(await resolveVariables(match, false, inContextOfFile)));
string = await replaceAsync(string, /\${path:(.*?)}/g, async (match: string) => path.normalize(await resolveVariables(match, false, inContextOfFile)));
} while (recursive && oldString !== string);
return string;
}
Expand Down

0 comments on commit dfa6072

Please sign in to comment.