[clang-tools-extra] r298696 - [clangd] Add support for vscode extension configuration

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 24 02:29:00 PDT 2017


Author: krasimir
Date: Fri Mar 24 04:29:00 2017
New Revision: 298696

URL: http://llvm.org/viewvc/llvm-project?rev=298696&view=rev
Log:
[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

Modified:
    clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
    clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=298696&r1=298695&r2=298696&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Fri Mar 24 04:29:00 2017
@@ -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
+}

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=298696&r1=298695&r2=298696&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Fri Mar 24 04:29:00 2017
@@ -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<T>(option: string, defaultValue?: any) : T {
+    const config = vscode.workspace.getConfiguration('clangd');
+    return config.get<T>(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<string>('path');
+    const clangdArgs = getConfig<string[]>('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
     const disposable = clangdClient.start();
 
     context.subscriptions.push(disposable, vscode.commands.registerCommand('clangd.applyFix', applyTextEdits));
-}
\ No newline at end of file
+}




More information about the cfe-commits mailing list