malaperle created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov.

Alt+o is used on Windows/Linux and Option+Cmd+o on macOS.

Signed-off-by: Marc-Andre Laperle <malape...@gmail.com>


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
@@ -1,6 +1,7 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
 import { realpathSync } from 'fs';
+import { RequestType, TextDocumentIdentifier } from 'vscode-languageclient';
 
 /**
  * Method to get workspace configuration option
@@ -12,6 +13,10 @@
     return config.get<T>(option, defaultValue);
 }
 
+export namespace SwitchSourceHeaderRequest {
+    export const type = new RequestType<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
@@ -55,4 +60,18 @@
     console.log('Clang Language Server is now active!');
 
     const disposable = clangdClient.start();
+    
+    context.subscriptions.push
+    
context.subscriptions.push(vscode.commands.registerCommand('clangd-vscode.switchheadersource',
 () => {
+        const uri = 
vscode.Uri.file(vscode.window.activeTextEditor.document.fileName);
+        if (!uri) {
+            return;
+        }
+        const docIdentifier = TextDocumentIdentifier.create(uri.toString());
+        clangdClient.sendRequest(SwitchSourceHeaderRequest.type, 
docIdentifier).then(sourceUri => {
+            if (sourceUri !== undefined) {
+                
vscode.workspace.openTextDocument(vscode.Uri.parse(sourceUri)).then(doc => 
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": "C/C++: Switch between Source/Header"
+            }
+        ],
+        "keybindings": [
+            {
+                "command": "clangd-vscode.switchheadersource",
+                "key": "Alt+o",
+                "mac": "Alt+cmd+o",
+                "when": "editorTextFocus"
+            }
+        ]
     }
 }


Index: clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -1,6 +1,7 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
 import { realpathSync } from 'fs';
+import { RequestType, TextDocumentIdentifier } from 'vscode-languageclient';
 
 /**
  * Method to get workspace configuration option
@@ -12,6 +13,10 @@
     return config.get<T>(option, defaultValue);
 }
 
+export namespace SwitchSourceHeaderRequest {
+    export const type = new RequestType<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
@@ -55,4 +60,18 @@
     console.log('Clang Language Server is now active!');
 
     const disposable = clangdClient.start();
+    
+    context.subscriptions.push
+    context.subscriptions.push(vscode.commands.registerCommand('clangd-vscode.switchheadersource', () => {
+        const uri = vscode.Uri.file(vscode.window.activeTextEditor.document.fileName);
+        if (!uri) {
+            return;
+        }
+        const docIdentifier = TextDocumentIdentifier.create(uri.toString());
+        clangdClient.sendRequest(SwitchSourceHeaderRequest.type, docIdentifier).then(sourceUri => {
+            if (sourceUri !== undefined) {
+                vscode.workspace.openTextDocument(vscode.Uri.parse(sourceUri)).then(doc => 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": "C/C++: Switch between Source/Header"
+            }
+        ],
+        "keybindings": [
+            {
+                "command": "clangd-vscode.switchheadersource",
+                "key": "Alt+o",
+                "mac": "Alt+cmd+o",
+                "when": "editorTextFocus"
+            }
+        ]
     }
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to