Skip to content

Commit

Permalink
fix: workaround for empty completion list + isIncomplete = true
Browse files Browse the repository at this point in the history
If Vscode receives emptuy completion list it ignores `isIncomplete` field.
Fixes: scalameta/metals#4756

Vscode issue: microsoft/vscode#155738
  • Loading branch information
dos65 committed Dec 27, 2022
1 parent 6155efe commit 1de2d86
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
Hover,
TextDocument,
tests as vscodeTextExplorer,
CompletionItem,
CompletionList,
} from "vscode";
import {
LanguageClient,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 1de2d86

Please sign in to comment.