Skip to content

Commit ea588aa

Browse files
authored
Add an option to allow "clangd.path" to point to a shell script (#730)
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 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
1 parent 4da3e1e commit ea588aa

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ recommend to run `npm run format` before sending a patch.
4848

4949
To create a new release, create a commit that:
5050

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

5454
Our CI will recognize the commit and publish new versions to the VSCode

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"description": "In restricted mode clangd.path and clangd.arguments are not respected.",
7979
"restrictedConfigurations": [
8080
"clangd.path",
81+
"clangd.useScriptAsExecutable",
8182
"clangd.arguments"
8283
]
8384
}
@@ -103,6 +104,12 @@
103104
"scope": "machine-overridable",
104105
"description": "The path to clangd executable, e.g.: /usr/bin/clangd."
105106
},
107+
"clangd.useScriptAsExecutable": {
108+
"type": "boolean",
109+
"default": "false",
110+
"scope": "machine-overridable",
111+
"description": "Allows the path to be a script e.g.: clangd.sh."
112+
},
106113
"clangd.arguments": {
107114
"type": "array",
108115
"default": [],

src/clangd-context.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,26 @@ export class ClangdContext implements vscode.Disposable {
6868
if (!clangdPath)
6969
return null;
7070

71-
const clangdArguments = await config.get<string[]>('arguments');
72-
73-
return new ClangdContext(clangdPath, clangdArguments, outputChannel);
71+
return new ClangdContext(clangdPath, outputChannel);
7472
}
7573

76-
private constructor(clangdPath: string, clangdArguments: string[],
77-
outputChannel: vscode.OutputChannel) {
74+
private constructor(clangdPath: string, outputChannel: vscode.OutputChannel) {
75+
const useScriptAsExecutable = config.get<boolean>('useScriptAsExecutable');
76+
let clangdArguments = config.get<string[]>('arguments');
77+
if (useScriptAsExecutable) {
78+
let quote = (str: string) => { return `"${str}"`; };
79+
clangdPath = quote(clangdPath)
80+
for (var i = 0; i < clangdArguments.length; i++) {
81+
clangdArguments[i] = quote(clangdArguments[i]);
82+
}
83+
}
7884
const clangd: vscodelc.Executable = {
7985
command: clangdPath,
8086
args: clangdArguments,
81-
options: {cwd: vscode.workspace.rootPath || process.cwd()}
87+
options: {
88+
cwd: vscode.workspace.rootPath || process.cwd(),
89+
shell: useScriptAsExecutable
90+
}
8291
};
8392
const traceFile = config.get<string>('trace');
8493
if (!!traceFile) {

0 commit comments

Comments
 (0)