diff --git a/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts b/clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts --- 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 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(