aboutsummaryrefslogtreecommitdiff
path: root/clangd/clients
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2017-03-01 16:16:29 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2017-03-01 16:16:29 +0000
commit6fbfc8451e5c1ce11298e2ec5b0f80cf02f78913 (patch)
tree9bdc78644e6505a7fbfb479c4b65c8c8e23fa507 /clangd/clients
parent72f44cc3ddb6e3004833058c8eafab2c68440243 (diff)
downloadclang-tools-extra-6fbfc8451e5c1ce11298e2ec5b0f80cf02f78913.tar.gz
[clangd] Add support for FixIts.
Summary: This uses CodeActions to show 'apply fix' actions when code actions are requested for a location. The actions themselves make use of a clangd.applyFix command which has to be implemented on the editor side. I included an implementation for vscode. This also adds a -run-synchronously flag which runs everything on the main thread. This is useful for testing. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30498 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@296636 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clangd/clients')
-rw-r--r--clangd/clients/clangd-vscode/src/extension.ts18
1 files changed, 17 insertions, 1 deletions
diff --git a/clangd/clients/clangd-vscode/src/extension.ts b/clangd/clients/clangd-vscode/src/extension.ts
index e57aa87a..36a5c9c0 100644
--- a/clangd/clients/clangd-vscode/src/extension.ts
+++ b/clangd/clients/clangd-vscode/src/extension.ts
@@ -18,9 +18,25 @@ export function activate(context: vscode.ExtensionContext) {
const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions);
+ function applyTextEdits(uri: string, edits: vscodelc.TextEdit[]) {
+ let textEditor = vscode.window.activeTextEditor;
+
+ if (textEditor && textEditor.document.uri.toString() === uri) {
+ textEditor.edit(mutator => {
+ for (const edit of edits) {
+ mutator.replace(vscodelc.Protocol2Code.asRange(edit.range), edit.newText);
+ }
+ }).then((success) => {
+ if (!success) {
+ vscode.window.showErrorMessage('Failed to apply fixes to the document.');
+ }
+ });
+ }
+ }
+
console.log('Clang Language Server is now active!');
const disposable = clangdClient.start();
- context.subscriptions.push(disposable);
+ context.subscriptions.push(disposable, vscode.commands.registerCommand('clangd.applyFix', applyTextEdits));
} \ No newline at end of file