[clang-tools-extra] 6ba0a4e - [clangd][vscode] Enable dot-to-arrow fixes in clangd completion.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 06:02:55 PDT 2020


Author: Haojian Wu
Date: 2020-03-09T14:02:08+01:00
New Revision: 6ba0a4ec3bbfe71050b7b5c87f46820f3500e211

URL: https://github.com/llvm/llvm-project/commit/6ba0a4ec3bbfe71050b7b5c87f46820f3500e211
DIFF: https://github.com/llvm/llvm-project/commit/6ba0a4ec3bbfe71050b7b5c87f46820f3500e211.diff

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

Summary:
The previous issue is that the item was filtered out by vscode, because
the prefix (which contains ".") are not matched against the filterText.

This patch works around it by adjusting the item filterText, inspired by
https://reviews.llvm.org/D75623.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75739

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts b/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
index 3d8ed2d65564..4749cd1bb582 100644
--- a/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
+++ b/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
@@ -65,6 +65,15 @@ class ClangdLanguageClient extends vscodelc.LanguageClient {
   }
 }
 
+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 @@ export function activate(context: vscode.ExtensionContext) {
         // 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
+        // 
diff erences 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 @@ export function activate(context: vscode.ExtensionContext) {
         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(


        


More information about the cfe-commits mailing list