[PATCH] D44158: [clangd:vscode] Resolve symlinks for file paths from clangd.

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 8 07:32:22 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327009: [clangd:vscode] Resolve symlinks for file paths from clangd. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44158

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


Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * 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 {
+function getConfig<T>(option: string, defaultValue?: any): T {
     const config = vscode.workspace.getConfiguration('clangd');
     return config.get<T>(option, defaultValue);
 }
@@ -24,18 +25,29 @@
     };
     const traceFile = getConfig<string>('trace');
     if (!!traceFile) {
-      const trace = {CLANGD_TRACE : traceFile};
-      clangd.options = {env : {...process.env, ...trace}};
+        const trace = { CLANGD_TRACE: traceFile };
+        clangd.options = { env: { ...process.env, ...trace } };
     }
     const serverOptions: vscodelc.ServerOptions = clangd;
 
     const filePattern: string = '**/*.{' +
-      ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
+        ['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: [{scheme: 'file', pattern: filePattern}],
+        documentSelector: [{ scheme: 'file', pattern: filePattern }],
         synchronize: !syncFileEvents ? undefined : {
             fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+        },
+        // Resolve symlinks for all files provided by clangd.
+        // This is a workaround for a bazel + clangd issue - bazel produces a symlink tree to build in,
+        // and when navigating to the included file, clangd passes its path inside the symlink tree
+        // rather than its filesystem path.
+        // FIXME: remove this once clangd knows enough about bazel to resolve the
+        // symlinks where needed (or if this causes problems for other workflows).
+        uriConverters: {
+            code2Protocol: (value: vscode.Uri) => value.toString(),
+            protocol2Code: (value: string) =>
+                vscode.Uri.file(realpathSync(vscode.Uri.parse(value).fsPath))
         }
     };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44158.137570.patch
Type: text/x-patch
Size: 2639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180308/532fe080/attachment.bin>


More information about the cfe-commits mailing list