12

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

Thatkookooguy
  • 5,356
  • 1
  • 24
  • 47

1 Answers1

5

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;
        },
        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.

elslooo
  • 9,814
  • 3
  • 37
  • 57
  • 1
    Great! That workaround worked great. This should totally be something we are allowed to control in some sort of real editor option :-) I hope this won't break anything else :-) – Thatkookooguy Nov 28 '19 at 15:25
  • 1
    In the suggested example all the other methods are unimplemented. Do I disable a default behavior here by specifying an own storage service? – PAX Mar 28 '21 at 06:50