Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Monaco completion list even if there are no matches

I have a custom CompletionItemProvider for Monaco editor. Is it possible to force Monaco show the completion list even if there are no matches?

For example, imagine that I always provide two completion items: abc and def:

  • If the user types a, then abc is shown
  • If the user types d, then def is shown
  • But if the user types z, then nothing is shown at all. Which makes sense by default. But how can I make both abc and def appear in this case anyway?

The use case is that our users might not be aware of using ctrl+space to trigger completion, so we would like to present completion list even if nothing matches so that the users can explore the options and possibly correct themselves.

like image 419
dennis Avatar asked Oct 27 '25 12:10

dennis


1 Answers

Your completion provider is called on every time a user types a letter. Let's assume you built a super simple provider that just returns ['abc', 'def'] each time it's called.

In that case you'll get the behavior you observe. Why? Because what triggered the provider is the user typing 'a' or 'd' or 'z' or something. If they type 'a' you'll only see 'abc' and if they type 'd' you'll only see 'def', and you'll get nothing if they type 'z'

If you want you can specify another trigger character, like space, or '.' that will open the entire list.

monaco.languages.registerCompletionItemProvider('javascript', {
    triggerCharacters: ['.', ' '],
    provideCompletionItems: ...
  });
like image 109
Cedric Dussud Avatar answered Oct 30 '25 14:10

Cedric Dussud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!