[PATCH] D41343: [clangd] in VSCode client, filter extensions properly and only accept file: URIs

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

sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, ilya-biryukov, klimek.

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.

  rCTE Clang Tools Extra



Index: clangd/clients/clangd-vscode/src/extension.ts
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -22,20 +22,20 @@
     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
             //        is implemented properly in clangd
             code2Protocol: (uri: vscode.Uri) : string => uri.toString(true),
             protocol2Code: (uri: string) : vscode.Uri => vscode.Uri.parse(uri)
         synchronize: !syncFileEvents ? undefined : {
-            fileEvents: vscode.workspace.createFileSystemWatcher('**/*.{' + cppFileExtensionsPattern + '}')
+            fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41343.127308.patch
Type: text/x-patch
Size: 1612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171218/ed6c499f/attachment-0001.bin>

More information about the cfe-commits mailing list