From af4adfa3ad25405fecd1828f9fef2f6568ad4117 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 24 Mar 2017 09:29:00 +0000 Subject: [PATCH] [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 --- .../clangd/clients/clangd-vscode/package.json | 23 +++++++++++++++++++++- .../clangd/clients/clangd-vscode/src/extension.ts | 18 +++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clangd/clients/clangd-vscode/package.json b/clang-tools-extra/clangd/clients/clangd-vscode/package.json index c991e63..6443b11 100644 --- a/clang-tools-extra/clangd/clients/clangd-vscode/package.json +++ b/clang-tools-extra/clangd/clients/clangd-vscode/package.json @@ -33,5 +33,26 @@ "mocha": "^2.3.3", "@types/node": "^6.0.40", "@types/mocha": "^2.2.32" + }, + "contributes": { + "configuration": { + "type": "object", + "title": "clangd configuration", + "properties": { + "clangd.path": { + "type": "string", + "default": "clangd", + "description": "The path to clangd executable, e.g.: /usr/bin/clangd" + }, + "clangd.arguments": { + "type": "array", + "default": [], + "items": { + "type": "string" + }, + "description": "Arguments for clangd server" + } + } + } } -} \ No newline at end of file +} diff --git a/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts b/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts index 36a5c9c..15dc8f1 100644 --- a/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts +++ b/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts @@ -2,14 +2,24 @@ import * as vscode from 'vscode'; import * as vscodelc from 'vscode-languageclient'; /** + * Method to get workspace configuration option + * @param option name of the option (e.g. for clangd.path should be path) + * @param defaultValue default value to return if option is not set + */ +function getConfig(option: string, defaultValue?: any) : T { + const config = vscode.workspace.getConfiguration('clangd'); + return config.get(option, defaultValue); +} + +/** * this method is called when your extension is activate * your extension is activated the very first time the command is executed */ export function activate(context: vscode.ExtensionContext) { - // TODO: make this configurable - const clangdPath = '/usr/bin/clangd'; + const clangdPath = getConfig('path'); + const clangdArgs = getConfig('arguments'); - const serverOptions: vscodelc.ServerOptions = { command: clangdPath }; + const serverOptions: vscodelc.ServerOptions = { command: clangdPath, args: clangdArgs }; const clientOptions: vscodelc.LanguageClientOptions = { // Register the server for C/C++ files @@ -39,4 +49,4 @@ export function activate(context: vscode.ExtensionContext) { const disposable = clangdClient.start(); context.subscriptions.push(disposable, vscode.commands.registerCommand('clangd.applyFix', applyTextEdits)); -} \ No newline at end of file +} -- 2.7.4