[PATCH] D75739: [clangd][vscode] Enable dot-to-arrow fixes in clangd completion.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 02:39:34 PDT 2020


hokein updated this revision to Diff 249046.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75739/new/

https://reviews.llvm.org/D75739

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


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
@@ -65,6 +65,15 @@
   }
 }
 
+class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
+  initialize() {}
+  fillClientCapabilities(capabilities: vscodelc.ClientCapabilities): void {
+    const extendedCompletionCapabilities: any =
+        capabilities.textDocument.completion;
+    extendedCompletionCapabilities.editsNearCursor = true;
+  }
+}
+
 /**
  *  this method is called when your extension is activate
  *  your extension is activated the very first time the command is executed
@@ -107,17 +116,18 @@
         // By adding the prefix to the beginning of the filterText, we get a perfect
         // fuzzymatch score for every item.
         // The sortText (which reflects clangd ranking) breaks the tie.
+        // This also prevents VSCode from filtering out any results due to the
+        // differences in how fuzzy filtering is applies, e.g. enable dot-to-arrow
+        // fixes in completion.
         //
         // We also have to mark the list as incomplete to force retrieving new rankings.
         // See https://github.com/microsoft/language-server-protocol/issues/898
         middleware: {
           provideCompletionItem: async (document, position, context, token, next) => {
-            // Get the incomplete identifier before the cursor.
-            let word = document.getWordRangeAtPosition(position);
-            let prefix = word && document.getText(new vscode.Range(word.start, position));
-            
             let list = await next(document, position, context, token);
             let items = (Array.isArray(list) ? list : list.items).map(item => {
+              // Gets the prefix used by vscode when doing fuzzymatch.
+              let prefix = document.getText(new vscode.Range(item.range.start, position))
               if (prefix)
                 item.filterText = prefix + "_" + item.filterText;
               return item;
@@ -137,6 +147,7 @@
         vscode.Disposable.from(semanticHighlightingFeature));
     clangdClient.registerFeature(semanticHighlightingFeature);
   }
+  clangdClient.registerFeature(new EnableEditsNearCursorFeature);
   console.log('Clang Language Server is now active!');
   context.subscriptions.push(clangdClient.start());
   context.subscriptions.push(vscode.commands.registerCommand(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75739.249046.patch
Type: text/x-patch
Size: 2563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200309/e1757c74/attachment-0001.bin>


More information about the cfe-commits mailing list