[PATCH] D54781: [clangd] Add 'Switch header/source' command in clangd-vscode

Marc-Andre Laperle via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 22 19:31:23 PST 2018


malaperle updated this revision to Diff 175078.
malaperle marked 5 inline comments as done.
malaperle added a comment.

Address comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54781

Files:
  clangd/clients/clangd-vscode/package.json
  clangd/clients/clangd-vscode/src/extension.ts


Index: clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -12,6 +12,12 @@
     return config.get<T>(option, defaultValue);
 }
 
+namespace SwitchSourceHeaderRequest {
+export const type =
+    new vscodelc.RequestType<vscodelc.TextDocumentIdentifier, string|undefined,
+                             void, void>('textDocument/switchSourceHeader');
+}
+
 /**
  *  this method is called when your extension is activate
  *  your extension is activated the very first time the command is executed
@@ -51,8 +57,25 @@
         }
     };
 
-    const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
-    console.log('Clang Language Server is now active!');
-
-    const disposable = clangdClient.start();
+  const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
+  console.log('Clang Language Server is now active!');
+  context.subscriptions.push(clangdClient.start());
+  context.subscriptions.push(vscode.commands.registerCommand(
+      'clangd-vscode.switchheadersource', async () => {
+        const uri =
+            vscode.Uri.file(vscode.window.activeTextEditor.document.fileName);
+        if (!uri) {
+          return;
+        }
+        const docIdentifier =
+            vscodelc.TextDocumentIdentifier.create(uri.toString());
+        const sourceUri = await clangdClient.sendRequest(
+            SwitchSourceHeaderRequest.type, docIdentifier);
+        if (!sourceUri) {
+          return;
+        }
+        const doc = await vscode.workspace.openTextDocument(
+            vscode.Uri.parse(sourceUri));
+        vscode.window.showTextDocument(doc);
+      }));
 }
Index: clangd/clients/clangd-vscode/package.json
===================================================================
--- clangd/clients/clangd-vscode/package.json
+++ clangd/clients/clangd-vscode/package.json
@@ -74,6 +74,20 @@
                     "description": "Names a file that clangd should log a performance trace to, in chrome trace-viewer JSON format."
                 }
             }
-        }
+        },
+        "commands": [
+            {
+                "command": "clangd-vscode.switchheadersource",
+                "title": "Switch between Source/Header"
+            }
+        ],
+        "keybindings": [
+            {
+                "command": "clangd-vscode.switchheadersource",
+                "key": "Alt+o",
+                "mac": "Alt+cmd+o",
+                "when": "editorTextFocus"
+            }
+        ]
     }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54781.175078.patch
Type: text/x-patch
Size: 2706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181123/5e536b1b/attachment.bin>


More information about the cfe-commits mailing list