From 1de2d86401409b91031a86945bcfbdd34de4233b Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Tue, 27 Dec 2022 16:42:42 +0300 Subject: [PATCH] fix: workaround for empty completion list + `isIncomplete = true` If Vscode receives emptuy completion list it ignores `isIncomplete` field. Fixes: https://github.com/scalameta/metals/issues/4756 Vscode issue: https://github.com/microsoft/vscode/issues/155738 --- src/extension.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 7b5071bee..227452103 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -29,6 +29,8 @@ import { Hover, TextDocument, tests as vscodeTextExplorer, + CompletionItem, + CompletionList, } from "vscode"; import { LanguageClient, @@ -301,6 +303,28 @@ function launchMetals( outputChannel: outputChannel, initializationOptions, middleware: { + provideCompletionItem: async ( + document, + position, + context, + token, + next + ) => { + let list = await next(document, position, context, token); + if (Array.isArray(list)) { + return list; + } else if (list) { + // workaround for https://github.com/scalameta/metals/issues/4756 + // original vscode issue https://github.com/microsoft/vscode/issues/155738 + let items = list.items; + if (list.isIncomplete && list.items.length == 0) { + // this item won't be rendered by vscode + let item = new CompletionItem("type more!!"); + items = [item]; + } + return new CompletionList(items, list.isIncomplete); + } + }, provideHover: hoverLinksMiddlewareHook, }, markdown: {