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

问题描述 投票:1回答:1

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

代码

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

javascript angular monaco-editor
1个回答
0
投票

您快到了。

您只需要返回{ 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

© www.soinside.com 2019 - 2024. All rights reserved.