Skip to content

Commit

Permalink
fix: workaround for empty completion list + isIncomplete = true (sc…
Browse files Browse the repository at this point in the history
…alameta#1278)

If Vscode receives emptuy completion list it ignores `isIncomplete` field.
Fixes: scalameta/metals#4756

Vscode issue: microsoft/vscode#155738
  • Loading branch information
dos65 authored Dec 27, 2022
1 parent 42a39db commit 5060b26
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
) => {
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: {
Expand Down

0 comments on commit 5060b26

Please sign in to comment.