在 Monaco Editor 中,如果使用标准的初始化,例如:
monaco.editor.create(document.getElementById("container"), {
value: "",
language: "csharp"
});
将拥有开箱即用的本地变量代码补全功能。例如,使用上面所述的标准初始化方式,并像这样输入代码:
string testVariable = "This is a string";
int aValue = 123;
代码补全功能将识别"testVariable"和"aValue"两个变量,并在代码补全列表中显示它们。
但是,如果我们在初始化中添加registerCompletionItemProvider,就像这样:
//Custom Code Completion function
function createCompleters() {
return [
{
label: 'customFunction1',
kind: monaco.languages.CompletionItemKind.Function,
documentation: "My first Custom Function",
insertText: 'customFunction1()'
},
{
label: 'customFunction2',
kind: monaco.languages.CompletionItemKind.Function,
documentation: "My second Custom Function",
insertText: 'customFunction2()'
}
];
}
//Register the custom completion function into Monaco Editor
monaco.languages.registerCompletionItemProvider('csharp', {
provideCompletionItems: function(model, position) {
return createCompleters();
}
});
//Continue with the Standard initialization here...
monaco.editor.create(document.getElementById("container"), {
value: "",
language: "csharp"
});
此时,本地变量将不再被识别,只有注册的函数被识别。
我如何注册自定义代码完成并仍然保留本地变量完成?谢谢!