Skip to content

Commit

Permalink
In VsCode 1.72 Node was updated to version 20, before this upgrade, i…
Browse files Browse the repository at this point in the history
…t was possible to execute cmd/bat scripts as executable.

     After this update this was suddenly broken.
     Our use-case for using such a script has to do with the consistency of our clang-tooling.
     We build clang-format, clang-tidy, clangd ... all together and put this in a package manager.
     In the script, we first download these executables (when needed) and than start the downloaded clangd.
     As such, when fixing an issue in clang-tidy, the same issue will get fixed in the clangd exe.
     Without this script, it is impossible to automatically trigger this download and it introduces the risk that we do not update all the tooling to the latest version.

Fixes #683

In this reapply, we quote both the command line and the arguments, such that both can contain spaces.
We also introduce the option useScriptAsExecutable, such that this is only enabled when the user wants it.
  • Loading branch information
JVApen committed Nov 18, 2024
1 parent 4da3e1e commit bb1d76e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ recommend to run `npm run format` before sending a patch.

To create a new release, create a commit that:

- increases the version number in `package.json`
- increases the version number in `package.json` and `package-lock.json`
- updates `CHANGELOG.md` to cover changes since the last release

Our CI will recognize the commit and publish new versions to the VSCode
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"description": "In restricted mode clangd.path and clangd.arguments are not respected.",
"restrictedConfigurations": [
"clangd.path",
"clangd.useScriptAsExecutable",
"clangd.arguments"
]
}
Expand All @@ -103,6 +104,12 @@
"scope": "machine-overridable",
"description": "The path to clangd executable, e.g.: /usr/bin/clangd."
},
"clangd.useScriptAsExecutable": {
"type": "boolean",
"default": "false",
"scope": "machine-overridable",
"description": "Allows the path to be a script e.g.: clangd.sh."
},
"clangd.arguments": {
"type": "array",
"default": [],
Expand Down
14 changes: 12 additions & 2 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,23 @@ export class ClangdContext implements vscode.Disposable {
if (!clangdPath)
return null;

const useScriptAsExecutable =
await config.get<boolean>('useScriptAsExecutable');
const clangdArguments = await config.get<string[]>('arguments');

return new ClangdContext(clangdPath, clangdArguments, outputChannel);
return new ClangdContext(clangdPath, clangdArguments, outputChannel,
useScriptAsExecutable);
}

private constructor(clangdPath: string, clangdArguments: string[],
outputChannel: vscode.OutputChannel) {
outputChannel: vscode.OutputChannel,
useScriptAsExecutable: boolean) {
if (useScriptAsExecutable) {
let quote = (str: string) => { return `"${str}"`; };
clangdPath = quote(clangdPath)
for (var i = 0; i < clangdArguments.length; i++)
clangdArguments[i] = quote(clangdArguments[i]);
}
const clangd: vscodelc.Executable = {
command: clangdPath,
args: clangdArguments,
Expand Down

0 comments on commit bb1d76e

Please sign in to comment.