[英]How can I get suggestions (registerCompletionItemProvider) to show between curly braces in for Markdown in Monaco?
When I create a completion item provider in Monaco for Markdown I'm unable to create suggestions for text between curly braces {}当我在摩纳哥为 Markdown 创建完成项提供程序时,我无法为花括号 {} 之间的文本创建建议
ie { typing in here won't launch the suggestions widget }
即
{ typing in here won't launch the suggestions widget }
I get that braces are reserved keywords in Markdown and are auto-closed in Monaco by default.我知道大括号是 Markdown 中的保留关键字,默认情况下在摩纳哥自动关闭。 Even if auto closing is off, once there is a matching ending curly brace autocomplete won't work.
即使自动关闭关闭,一旦有匹配的结束花括号自动完成将不起作用。
Is there an option to make this work?有没有办法使这项工作? Or will I have to make a new language that is basically a copy of Markdown that doesn't register curly braces as a bracket?
或者我是否必须创建一种新语言,它基本上是 Markdown 的副本,没有将花括号注册为括号?
Here's a monaco editor playground snippet that shows this issue这是显示此问题的摩纳哥编辑器游乐场片段
monaco.languages.registerCompletionItemProvider('markdown', {
provideCompletionItems: function() {
return {
suggestions: [
{
label: "random_number",
insertText: "random_number"
},
{
label: "now",
insertText: "now"
},
{
label: "today",
insertText: "today"
},
]
};
}
});
monaco.editor.create(document.getElementById("container"), {
value: "# hello.\n{autocomplete doesn't work between braces: }\nbut it works outside: ",
language: "markdown"
});
Bit more info: it's possible the reason suggestions aren't launching is that Markdown treats anything between curly braces { } as a token and colors it.更多信息:建议未启动的原因可能是 Markdown 将大括号 { } 之间的任何内容视为标记,而 colors 将其视为标记。
https://github.com/microsoft/monaco-languages/blob/618f2cff2d8e72f04fe9d63085a0c5118b80e8a0/src/markdown/markdown.ts#L143 https://github.com/microsoft/monaco-languages/blob/618f2cff2d8e72f04fe9d63085a0c5118b80e8a0/src/markdown/markdown.ts#L143
Not clear why this is necessary though.不清楚为什么这是必要的。
It seems to work fine with your originally-posted code.它似乎适用于您最初发布的代码。 Perhaps you are expecting it to auto-suggest based on the current word, if one were to break up the text within the curly braces into separate words?
如果要将大括号内的文本分解成单独的词,您可能希望它根据当前词自动建议? Keep in mind that
{...}
is a single token, so autocomplete will try to match the prefix consisting of all of the text starting with the first char after the bracket until the cursor position-- ie if the text is {hello there how are you}
and the cursor position is 12 (after "there"), the prefix to match to is "hello there" and not just "there":请记住
{...}
是单个标记,因此自动完成将尝试匹配由括号后的第一个字符开始直到 cursor 位置的所有文本组成的前缀——即如果文本是{hello there how are you}
cursor position 是 12(在“那里”之后),要匹配的前缀是“你好”,而不仅仅是“那里”:
Which is from your original code, with one additional suggestion:这是来自您的原始代码,还有一个额外的建议:
monaco.languages.registerCompletionItemProvider('markdown', {
provideCompletionItems: function() {
return {
suggestions: [
{
label: "random_number",
insertText: "random_number"
},
{
label: "now",
insertText: "now"
},
{
label: "today",
insertText: "today"
},
{
label: "autocomplete does work fine between braces",
insertText: "autocomplete does work fine between braces"
},
]
};
}
});
monaco.editor.create(document.getElementById("container"), {
value: "# hello.\n{autocomplete doesn't work between braces: }\nbut it works outside: ",
language: "markdown"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.