1
1
import * as vscode from 'vscode' ;
2
2
import * as vscodelc from 'vscode-languageclient' ;
3
3
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
+
4
14
/**
5
15
* this method is called when your extension is activate
6
16
* your extension is activated the very first time the command is executed
7
17
*/
8
18
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' ) ;
11
21
12
- const serverOptions : vscodelc . ServerOptions = { command : clangdPath } ;
22
+ const serverOptions : vscodelc . ServerOptions = { command : clangdPath , args : clangdArgs } ;
13
23
14
24
const clientOptions : vscodelc . LanguageClientOptions = {
15
25
// Register the server for C/C++ files
@@ -39,4 +49,4 @@ export function activate(context: vscode.ExtensionContext) {
39
49
const disposable = clangdClient . start ( ) ;
40
50
41
51
context . subscriptions . push ( disposable , vscode . commands . registerCommand ( 'clangd.applyFix' , applyTextEdits ) ) ;
42
- }
52
+ }
0 commit comments