使用Monaco编辑器禁用所有已用词的自动完成功能

时间:2019-06-03 15:39:07

标签: monaco-editor

如果从ProvideCompletionItems返回了一个空数组,则自动完成功能会建议所有已使用的单词。我可以禁用此行为吗?

我在摩纳哥游乐场示例中重新创建了行为: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-completion-provider-example

function createDependencyProposals() {
    // returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
    // here you could do a server side lookup
    return [
    ];
}


monaco.languages.registerCompletionItemProvider('json', {
    provideCompletionItems: function(model, position) {
        // find out if we are completing a property in the 'dependencies' object.
        var textUntilPosition = model.getValueInRange({startLineNumber: 1, startColumn: 1, endLineNumber: position.lineNumber, endColumn: position.column});
        var match = textUntilPosition.match(/"dependencies"\s*:\s*{\s*("[^"]*"\s*:\s*"[^"]*"\s*,\s*)*("[^"]*)?$/);
        var suggestions = match ? createDependencyProposals() : [];
        return {
            suggestions: suggestions
        };
    }
});

monaco.editor.create(document.getElementById("container"), {
    value: "{\n\t\"dependencies\": {\n\t\t\n\t}\n}\n",
    language: "json"
});

A screenshot of the autocompleted list

0 个答案:

没有答案