Skip to content

Commit da913be

Browse files
authored
Add an option to allow "clangd.path" to point to a shell script
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
1 parent 4a6319a commit da913be

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
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: 8 additions & 1 deletion
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": [],
@@ -397,4 +404,4 @@
397404
]
398405
}
399406
}
400-
}
407+
}

src/clangd-context.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,22 @@ export class ClangdContext implements vscode.Disposable {
7676
private constructor(subscriptions: vscode.Disposable[], clangdPath: string,
7777
outputChannel: vscode.OutputChannel) {
7878
this.subscriptions = subscriptions;
79-
const clangdArguments = config.get<string[]>('arguments');
79+
const useScriptAsExecutable = config.get<boolean>('useScriptAsExecutable');
80+
let clangdArguments = config.get<string[]>('arguments');
81+
if (useScriptAsExecutable) {
82+
let quote = (str: string) => { return `"${str}"`; };
83+
clangdPath = quote(clangdPath)
84+
for (var i = 0; i < clangdArguments.length; i++) {
85+
clangdArguments[i] = quote(clangdArguments[i]);
86+
}
87+
}
8088
const clangd: vscodelc.Executable = {
8189
command: clangdPath,
8290
args: clangdArguments,
83-
options: {cwd: vscode.workspace.rootPath || process.cwd()}
91+
options: {
92+
cwd: vscode.workspace.rootPath || process.cwd(),
93+
shell: useScriptAsExecutable
94+
}
8495
};
8596
const traceFile = config.get<string>('trace');
8697
if (!!traceFile) {

0 commit comments

Comments
 (0)