简体   繁体   English

始终在 monaco-editor 中显示“显示更多”部分

[英]Always show the "Show more" section in monaco-editor

I'm working with the Configure javascript defaults example from the monaco editor playground.我正在使用来自摩纳哥编辑器游乐场的Configure javascript defaults示例。

https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-javascript-defaults 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.当我开始输入预定义的 class 时,我会自动完成,但我需要按一次 ctl+space 才能查看建议的实际文档。

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 :现在如何打开:

在此处输入图像描述

How I want it to open by default :希望它如何默认打开

在此处输入图像描述

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.存储服务还用于记住最近使用的建议(以个性化 IntelliSense)等,因此如果您需要该功能,您可能还想实现其他功能。 A complete interface with descriptions of what each method should do is IStorageService .一个完整的接口描述了每个方法应该做什么是IStorageService

In monaco-editor-core@0.34.0 the workaround mentioned in this comment needs to be extended with onDidChangeValue function as well.monaco-editor-core@0.34.0中,此评论中提到的解决方法也需要使用onDidChangeValue function 进行扩展。 The resulting structure will look as follows:生成的结构如下所示:

    storageService: {
      get() {},
      getBoolean(key) {
        return key === 'expandSuggestionDocs';
      },
      getNumber() {
        return 0;
      },
      remove() {},
      store() {},
      onWillSaveState() {},
      onDidChangeStorage() {},
      onDidChangeValue() {},
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM