Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always show the "Show more" section in monaco-editor

I'm working with the Configure javascript defaults example from the monaco editor playground.

https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-javascript-defaults

When I start typing the pre-defined class, I get autocompletion, but I need to hit ctl+space one time to see the actual documentation of the suggestions.

Is there a way to set this option by default so that autocompletion will show the docs by default open?

This is the only thing I changed in the code:

monaco.languages.typescript.typescriptDefaults.addExtraLib([
  '/**',
  ' * Know your facts!',
  ' */',
  'declare class Facts {',
  '    /**',
  '     * Returns the next fact',
  '     */',
  '    static next():string',
  '}',
].join('\n'), 'filename/facts.d.ts');

How it opens right now:

enter image description here

How I want it to open by default:

enter image description here

like image 955
Thatkookooguy Avatar asked Feb 20 '19 21:02

Thatkookooguy


People also ask

How do I add text to Monaco editor?

Show activity on this post. var selection = editor. getSelection(); var id = { major: 1, minor: 1 }; var text = "XXX"; var op = {identifier: id, range: selection, text: text, forceMoveMarkers: true}; editor. executeEdits("my-source", [op]);

What is Monaco editor used for?

The Monaco Editor is the code editor that powers VS Code. A good page describing the code editor's features is here. It is licensed under the MIT License and supports Edge, Chrome, Firefox, Safari and Opera. The Monaco editor is not supported in mobile browsers or mobile web frameworks.


1 Answers

Just in case anyone's still wondering: as a workaround you can implement your own storage service which (among other things) will also be used to query the current preference of suggestion expansion.

monaco.editor.create(document.getElementById("container"), {
    value: jsCode,
    language: "javascript"
}, {
    storageService: {
        get() {},
        getBoolean(key) {
            if (key === "expandSuggestionDocs")
                return true;

            return false;
        },
        remove() {},
        store() {},
        onWillSaveState() {},
        onDidChangeStorage() {}
    }
});

The storage service is also used for things like remembering most recently used suggestions (to personalize IntelliSense) etc., so if you need that functionality you may want to implement the other functions as well. A complete interface with descriptions of what each method should do is IStorageService.

like image 104
cutsoy Avatar answered Oct 24 '22 22:10

cutsoy