Monaco自动完成无法列出符号。

huangapple go评论63阅读模式
英文:

Monaco auto completion can't list symbols

问题

我正在使用Monaco Editor并创建自定义语言。我正在使用monaco.languages.registerCompletionItemProvider来进行自动完成。当我想要自动完成的单词列表时,它运行良好,但是当我想要自动完成的符号列表时,似乎无法列出我的符号。因此,我希望"值"变量在"标签"中列出,而不是"k"列为标签,但由于它们是符号,所以无法实现。是否有任何解决方法?

以下是您提供的代码部分:

var op = new Map([]);
op.set('and', '∧');
op.set('or', '∨');
op.set('implies','→');
op.set('not', '¬');
op.set('forall','∀');
op.set('exists','∃');
op.set('turnstile','⊢');
let operators = ['and', 'or', 'implies', 'not', 'forall', 'exists','turnstile'];

monaco.languages.registerCompletionItemProvider('logium', {
    provideCompletionItems: (model, position) => {
        const suggestions = [
            ...operators.map(k => {
                let value = op.get(k);
                return {
                    label : k,
                    kind: monaco.languages.CompletionItemKind.Function,
                    insertText: value
                };
            }),   
        ];
        return {suggestions: suggestions};
    }
})

第一张图片显示了当我将"k"作为"标签"时的效果,第二张图片显示了当我将"value"作为"标签"时的效果。

英文:

So, I am using Monaco Editor and creating my custom language. I am using the monaco.languages.registerCompletionItemProvider for auto completion for my language. I can't seem to figure auto how to list my symbols in the auto completion list. It works well when I want a list of words for auto completion but it does not work when I want a list of symbols. So, I want the
"value" variable to be listed as the "label", instead of "k" listed as the label, but it can't because they are symbols. Are there any workarounds?

    var op = new Map([])
    op.set('and', '∧');
    op.set('or', '∨');
    op.set('implies','→');
    op.set('not', '¬');
    op.set('forall','∀');
    op.set('exists','∃');
    op.set('turnstile','⊢');
    let operators = ['and', 'or', 'implies', 'not', 'forall', 'exists','turnstile'];

monaco.languages.registerCompletionItemProvider('logium', {
            provideCompletionItems: (model, position) => {
                const suggestions = [
                     ...operators.map(k => {
                        let value = getByKey(op, k);
                         return {
                             label : k,
                             kind: monaco.languages.CompletionItemKind.Function,
                             insertText: value
                         };
                     }),   
                    ];
                return {suggestions: suggestions};
            }
        })

Here is a picture of how it looks when I have "k" as my "label":

Monaco自动完成无法列出符号。

And here is a picture of how it look when I have "value" as my "label":

Monaco自动完成无法列出符号。

答案1

得分: 1

这是自动完成,意味着它会完成用户已经输入的内容。如果您有单个字母的建议,而且用户已经输入了一个字母,但这个字母不匹配任何建议,那么不会显示任何建议。您必须显示用户可以输入的值,而不是您想要插入的值。

英文:

Don't forget this is auto completion, which means it completes what the user already typed. If you have single letter suggestions and one letter was also typed, which doesn't match any of the suggestions, then no suggestion is shown. You have to show the values which the user can type, not the values you want to insert instead.

huangapple
  • 本文由 发表于 2023年2月24日 04:59:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550272.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定