mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-23 07:52:06 +00:00
[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
This commit is contained in:
parent
684d6fdee2
commit
6ba0a4ec3b
@ -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
|
||||
// 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 @@ 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(
|
||||
|
Loading…
Reference in New Issue
Block a user