How can I implement more languages support in Monaco Editor?

Viewed 3691

I want to use Monaco Editor for a personal project , but I saw that it just come with default support for html/css/javascript

I want it to have support for more languages like Java or Python

I could not find any clear tutorial on how to implement this so if anyone did this already or have some idea of how to do it I would appreciate a help

1 Answers

Monaco comes with basic colorization for Java and Python (along with a bunch of other languages). If you are interested in writing your own language service for a particular language, this playground example should give you more than enough to get a prototype working.

If you want custom syntax highlighting for some language, monaco allows this using a related library, monarch which allows you to specify the highlighter using JSON.

Since your question is a bit vague, you should clarify what you are trying to do in your project. If you are looking to replicate the functionality provided by vscode and a proper language server extension (for example, vscode-java), you'd need to implement a custom language server for your application (link provided in the first paragraph) which is surprisingly easy due to the nice API provided by monaco, but it is still not a trivial task.

On the other hand, if all you want is syntax highlighting/coloring for language A, B, etc., either take advantage of the ones provided by monaco or look into a third-party or custom monarch highlighter. Hope this helps.

Related