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 clangd#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 5a0a823 commit e0e1341
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Version 0.1.31: November 13, 2024

* Reverted [#708](https://github.com/clangd/vscode-clangd/pull/708) and [#715](https://github.com/clangd/vscode-clangd/pull/715) for causing [#722](https://github.com/clangd/vscode-clangd/issues/722)

## Version 0.1.30: November 13, 2024

* Added option to disable hovers [#703](https://github.com/clangd/vscode-clangd/pull/703)
Expand Down
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-clangd",
"displayName": "clangd",
"description": "C/C++ completion, navigation, and insights",
"version": "0.1.30",
"version": "0.1.31",
"publisher": "llvm-vs-code-extensions",
"license": "MIT",
"homepage": "https://clangd.llvm.org/",
Expand Down 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
17 changes: 13 additions & 4 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,25 @@ export class ClangdContext implements vscode.Disposable {

async activate(globalStoragePath: string,
outputChannel: vscode.OutputChannel) {
const clangdPath = await install.activate(this, globalStoragePath);
var clangdPath = await install.activate(this, globalStoragePath);
if (!clangdPath)
return;

var clangdArguments = await config.get<string[]>('arguments');
const useShell = await config.get<boolean>('useScriptAsExecutable');
if (useShell) {
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 = {
// Quote the path. With `shell: true`, this is needed
// in case the path contains spaces.
command: `"${clangdPath}"`,
args: await config.get<string[]>('arguments'),
options: {cwd: vscode.workspace.rootPath || process.cwd(), shell: true}
command: clangdPath,
args: clangdArguments,
options:
{cwd: vscode.workspace.rootPath || process.cwd(), shell: useShell}
};
const traceFile = config.get<string>('trace');
if (!!traceFile) {
Expand Down

0 comments on commit e0e1341

Please sign in to comment.