Monaco-editor: Add a new language and its formatter to Monaco Editor

Created on 16 Jan 2018  路  9Comments  路  Source: microsoft/monaco-editor

I want to add a language of Excel formulas to Monaco Editor. I understand I need to follow this approach and especially add excelformulas.ts.

One important functionality I want to realise is to format a formula. For example, given =sum(1, 2, 3), I want to format it to

=sum(1,
     2,
     3)

So somewhere I need to add a formatter. There are a lot of formatters in VSCode marketplace, and I understand we could follow this way to make a VSCode extension. But could anyone tell me how to make a formatter extension for Monaco Editor? Otherwise, how could we integrate the formatting functionality directly into Monaco Editor?

Thank you

All 9 comments

@chengtie you can register formatting providers for your language with following api:

monaco.languages.registerDocumentFormattingEditProvider(...)
monaco.languages.registerDocumentRangeFormattingEditProvider(...)
monaco.languages.registerOnTypeFormattingEditProvider(...)

Hi. @chengtie. I read your problem. I have an exactly same problem like that. Want to add Excel formula but don't know where to start. Is there anyone can help me out?

Thank you.

may be somebody know exists open source formatting lib or example for excel ?

I'm also trying to add formulas - please share your solution if you've figured it out :)

I did my own language based on https://github.com/Microsoft/monaco-languages

Would you share a gist? I would greatly appreciate :)

@ButuzGOL How do you make Monaco load your new language? I also tried to clone of those languages but then the loader doesn't know about it.

A playground demonstrating how to do this:
https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages

Was this page helpful?
0 / 5 - 0 ratings