Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autosuggest for JSON files with custom schema for Monaco editor?

I use online Monaco editor sample Configures two JSON schemas, with references
While it works fine, in order to receive an intellisense I have to press Ctrl+Space (i.e. it doesn't appear automatically):

enter image description here
However, in VSCode (which uses Monaco), it appears instantly as soon as I type the first quotation mark:

enter image description here

How should I change Monaco's code sample to behave exactly as in VSCode?

like image 365
Kai Avatar asked Nov 06 '22 18:11

Kai


1 Answers

Currently, I managed to work around it by using below code:

this.editor.onKeyUp((e) => {
      const position = this.editor.getPosition();
      const text = this.editor.getModel().getLineContent(position.lineNumber).trim();
      if (e.keyCode === monaco.KeyCode.Enter && !text) {
        this.editor.trigger('', 'editor.action.triggerSuggest', '');
      }
    });

We detect the "Enter" keypress and check if we are at a new line. If yes, trigger suggestions.

like image 108
Kai Avatar answered Nov 11 '22 15:11

Kai