From 5060b26935b30da9b224e43b2eb24269cccf10ff Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Tue, 27 Dec 2022 18:36:19 +0300 Subject: [PATCH] fix: workaround for empty completion list + `isIncomplete = true` (#1278) 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..535f57bc0 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 + ) => { + const 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 + if (list.isIncomplete && list.items.length == 0) { + // this item won't be rendered by vscode + const item = new CompletionItem("type more!!"); + return new CompletionList([item], true); + } else { + return list; + } + } + }, provideHover: hoverLinksMiddlewareHook, }, markdown: {