Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Monaco Editor custom language in angular? [closed]

I have tried to create custom language with auto complete ( intellisenses ). It's not working out. can any one help me to achieve this.

Code

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

like image 702
bagya Avatar asked Dec 17 '19 15:12

bagya


People also ask

How do I start Monaco editor?

You'll need to copy the files from node_modules/monaco-editor/min/vs to your preferred location of choice. Since I'm using ASP.NET Core, I use gulp to copy the files from node_modules to wwwroot/js/vs . Here is condensed sample of how to set up the Monaco Editor, since I could not find a quick start elsewhere.


1 Answers

You're almost there.

You only need to return object like { suggestions: suggestions } instead of array in your provideCompletionItems method and you're done:

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

like image 186
yurzui Avatar answered Oct 19 '22 09:10

yurzui