Skip to content

Commit

Permalink
Add an option to allow "clangd.path" to point to a shell script
Browse files Browse the repository at this point in the history
In VSCode 1.92 and later (which uses node 20), this requires passing `shell: true` in the executable options.

However, using `shell: true` changes the behavior in some other ways, e.g. the path and arguments now have to be quoted in case they contain spaces.

To avoid the potential for regressions from using `shell: true`, its use is made conditional on a new clangd option, "clangd.useScriptAsExecutable".

Fixes #683
  • Loading branch information
JVApen authored Dec 22, 2024
1 parent 4a6319a commit da913be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 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
9 changes: 8 additions & 1 deletion 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 Expand Up @@ -397,4 +404,4 @@
]
}
}
}
}
15 changes: 13 additions & 2 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,22 @@ export class ClangdContext implements vscode.Disposable {
private constructor(subscriptions: vscode.Disposable[], clangdPath: string,
outputChannel: vscode.OutputChannel) {
this.subscriptions = subscriptions;
const clangdArguments = config.get<string[]>('arguments');
const useScriptAsExecutable = config.get<boolean>('useScriptAsExecutable');
let clangdArguments = config.get<string[]>('arguments');
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,
options: {cwd: vscode.workspace.rootPath || process.cwd()}
options: {
cwd: vscode.workspace.rootPath || process.cwd(),
shell: useScriptAsExecutable
}
};
const traceFile = config.get<string>('trace');
if (!!traceFile) {
Expand Down

0 comments on commit da913be

Please sign in to comment.