简体   繁体   English

自定义完成显示顺序-摩纳哥

[英]Custom order of display of completions - monaco

I am referring to the completion-provider-example for monaco. 我指的是摩纳哥的完成提供商示例

I noticed that the completions are defined in this order: lodash, express, mkdirp but the suggestions in the editor are listed alphabetically. 我注意到完成是按以下顺序定义的: lodash, express, mkdirp但是编辑器中的建议按字母顺序列出。

I would like to customize this behaviour. 我想自定义此行为。 Is this possible? 这可能吗? I have looked at this pull request , but can't get it wired up. 我已经看过这个拉取请求 ,但是无法将其连接起来。

Any help is appreciated! 任何帮助表示赞赏!

In the example that you link to, simply add the sortText key to each completion item. 在链接到的示例中,只需将sortText键添加到每个完成项。 This value is used for determining the order of the items in the completion box. 此值用于确定完成框中项目的顺序。

Modification to linked example: 修改链接示例:

return [
    {
        label: '"lodash"',
        kind: monaco.languages.CompletionItemKind.Function,
        documentation: "The Lodash library exported as Node.js modules.",
        insertText: '"lodash": "*"',
        sortText: 'a'
    },
    {
        label: '"express"',
        kind: monaco.languages.CompletionItemKind.Function,
        documentation: "Fast, unopinionated, minimalist web framework",
        insertText: '"express": "*"',
        sortText: 'b'
    },
    {
        label: '"mkdirp"',
        kind: monaco.languages.CompletionItemKind.Function,
        documentation: "Recursively mkdir, like <code>mkdir -p</code>",
        insertText: '"mkdirp": "*"',
        sortText: 'c'
    }
];

The sortText values 'a', 'b', 'c' now determine the order of the suggestions. 现在,sortText值'a','b','c'确定建议的顺序。

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

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