[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
Fri Mar 6 06:37:02 PST 2020
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
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.
Repository:
rG LLVM Github Monorepo
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,14 @@
}
}
+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
@@ -112,12 +120,27 @@
// 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 => {
+ // ^ is the position.
+ // Example 1: std::u_p^
+ // Example 2: a.f^
+ //
+ // When run code completion in VSCode, what happens:
+ // - clangd returns a completion item with range [[u_p]] and filterText "unique_ptr"
+ // - vscode extracts the word (prefix we called) from the range , which is "u_p"
+ // - vscode fuzzy-matches the filterText "unique_ptr" against the prefix "u_p"
+ //
+ // For example 2, the completion item range is [[.f]], filterText
+ // is "foo", insertText is "->foo". ".f" is the prefix used to do
+ // fuzzymatch, and the filterText "foo" is not matched, therefore
+ // the item is filtered out and not shown in the UI.
+ //
+ // Adding the prefix to the filterText will prevent VSCode filtering
+ // it out.
+
+ // 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 +160,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.248715.patch
Type: text/x-patch
Size: 2999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200306/6f734c4e/attachment.bin>
More information about the cfe-commits
mailing list