Skip to content

Commit

Permalink
Add an option to allow "clangd.path" to point to a shell script (#730)
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 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 Nov 20, 2024
1 parent 4da3e1e commit ea588aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 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
21 changes: 15 additions & 6 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,26 @@ export class ClangdContext implements vscode.Disposable {
if (!clangdPath)
return null;

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

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

private constructor(clangdPath: string, clangdArguments: string[],
outputChannel: vscode.OutputChannel) {
private constructor(clangdPath: string, outputChannel: vscode.OutputChannel) {
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 ea588aa

Please sign in to comment.