如何以角度创建Monaco Editor自定义语言?

时间:2019-12-17 15:22:05

标签: javascript angular monaco-editor

我尝试用自动完成(intellisenses)创建自定义语言。它没有解决。谁能帮助我实现这一目标。

代码

https://stackblitz.com/edit/angular-7-master-emjqsr?file=src/app/app.module.ts

1 个答案:

答案 0 :(得分:1)

您快到了。

您只需要返回{ suggestions: suggestions }之类的对象,而不是provideCompletionItems方法中的数组,就可以完成:

monaco.languages.registerCompletionItemProvider('dummy', {
  provideCompletionItems: () => {
    var suggestions = [
      {
        label: 'simpleText',
        kind: monaco.languages.CompletionItemKind.Text,
        insertText: 'simpleText',
      },
      {
        label: 'testing',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'testing(${1:condition})',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
      },
      {
        label: 'ifelse',
        kind: monaco.languages.CompletionItemKind.Snippet,
        insertText: ['if (${1:condition}) {', '\t$0', '} else {', '\t', '}'].join('\n'),
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        documentation: 'If-Else Statement',
      },
    ];
    return { suggestions: suggestions };
  },
});

Ng-run Example