[clang-tools-extra] r320972 - [clangd] in VSCode client, filter extensions properly and only accept file: URIs

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 03:29:45 PST 2017


Author: sammccall
Date: Mon Dec 18 03:29:45 2017
New Revision: 320972

URL: http://llvm.org/viewvc/llvm-project?rev=320972&view=rev
Log:
[clangd] in VSCode client, filter extensions properly and only accept file: URIs

Summary:
The filtering wasn't previously working as intended - the string list is
interpreted as a list of editor modes, not file extensions.
(It happens to mostly work as "c" and "cpp" are the names of modes, but we're
missing objective-c)

The file: restriction is new - clangd needs to be able to convert URI<->path
in order to determine how to build.

Reviewers: hokein

Subscribers: klimek, ilya-biryukov, cfe-commits

Differential Revision: https://reviews.llvm.org/D41343

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

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=320972&r1=320971&r2=320972&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 Mon Dec 18 03:29:45 2017
@@ -22,11 +22,11 @@ export function activate(context: vscode
 
     const serverOptions: vscodelc.ServerOptions = { command: clangdPath, args: clangdArgs };
 
-    const cppFileExtensions: string[] = ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'];
-    const cppFileExtensionsPattern = cppFileExtensions.join();
+    const filePattern: string = '**/*.{' +
+      ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
     const clientOptions: vscodelc.LanguageClientOptions = {
         // Register the server for C/C++ files
-        documentSelector: cppFileExtensions,
+        documentSelector: [{scheme: 'file', pattern: filePattern}],
         uriConverters: {
             // FIXME: by default the URI sent over the protocol will be percent encoded (see rfc3986#section-2.1)
             //        the "workaround" below disables temporarily the encoding until decoding
@@ -35,7 +35,7 @@ export function activate(context: vscode
             protocol2Code: (uri: string) : vscode.Uri => vscode.Uri.parse(uri)
         },
         synchronize: !syncFileEvents ? undefined : {
-            fileEvents: vscode.workspace.createFileSystemWatcher('**/*.{' + cppFileExtensionsPattern + '}')
+            fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
         }
     };
 




More information about the cfe-commits mailing list