Skip to content

Commit af4adfa

Browse files
committedMar 24, 2017
[clangd] Add support for vscode extension configuration
Summary: Adds vscode workspace level configuration options for path to clangd binary and its arguments. Contributed by stanionascu! Reviewers: cfe-commits, bkramer, krasimir Reviewed By: krasimir Differential Revision: https://reviews.llvm.org/D31121 llvm-svn: 298696
1 parent 45bbe01 commit af4adfa

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed
 

Diff for: ‎clang-tools-extra/clangd/clients/clangd-vscode/package.json

+22-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,26 @@
3333
"mocha": "^2.3.3",
3434
"@types/node": "^6.0.40",
3535
"@types/mocha": "^2.2.32"
36+
},
37+
"contributes": {
38+
"configuration": {
39+
"type": "object",
40+
"title": "clangd configuration",
41+
"properties": {
42+
"clangd.path": {
43+
"type": "string",
44+
"default": "clangd",
45+
"description": "The path to clangd executable, e.g.: /usr/bin/clangd"
46+
},
47+
"clangd.arguments": {
48+
"type": "array",
49+
"default": [],
50+
"items": {
51+
"type": "string"
52+
},
53+
"description": "Arguments for clangd server"
54+
}
55+
}
56+
}
3657
}
37-
}
58+
}

Diff for: ‎clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import * as vscode from 'vscode';
22
import * as vscodelc from 'vscode-languageclient';
33

4+
/**
5+
* Method to get workspace configuration option
6+
* @param option name of the option (e.g. for clangd.path should be path)
7+
* @param defaultValue default value to return if option is not set
8+
*/
9+
function getConfig<T>(option: string, defaultValue?: any) : T {
10+
const config = vscode.workspace.getConfiguration('clangd');
11+
return config.get<T>(option, defaultValue);
12+
}
13+
414
/**
515
* this method is called when your extension is activate
616
* your extension is activated the very first time the command is executed
717
*/
818
export function activate(context: vscode.ExtensionContext) {
9-
// TODO: make this configurable
10-
const clangdPath = '/usr/bin/clangd';
19+
const clangdPath = getConfig<string>('path');
20+
const clangdArgs = getConfig<string[]>('arguments');
1121

12-
const serverOptions: vscodelc.ServerOptions = { command: clangdPath };
22+
const serverOptions: vscodelc.ServerOptions = { command: clangdPath, args: clangdArgs };
1323

1424
const clientOptions: vscodelc.LanguageClientOptions = {
1525
// Register the server for C/C++ files
@@ -39,4 +49,4 @@ export function activate(context: vscode.ExtensionContext) {
3949
const disposable = clangdClient.start();
4050

4151
context.subscriptions.push(disposable, vscode.commands.registerCommand('clangd.applyFix', applyTextEdits));
42-
}
52+
}

0 commit comments

Comments
 (0)
Please sign in to comment.