Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monaco editor matchBrackets do not highlight

I'm defining new language in monaco-editor. I expect that it automatically highlight matching brackets and parentheses because by default matchBrackets option is true.

Should I do anything else?

Sample Code: Look at this page it doesn't work in Microsoft's samples codes too.

like image 593
Iman Mahmoudinasab Avatar asked Nov 14 '17 09:11

Iman Mahmoudinasab


People also ask

How do you make a Monaco editor readOnly?

editor . create( document. getElementById('ide'), { model: null, readOnly: true, contextmenu: false, } ); So now that editor is readonly.

How do I use editor in react in Monaco?

Starting from version v4. 4.0 it's possible to use monaco-editor as an npm package; import it from node_modules and include monaco sources into your bundle (instead of using CDN). To make it work you can do the following: import * as monaco from "monaco-editor"; import { loader } from "@monaco-editor/react"; loader.

What is the use of Monaco editor?

The Monaco Editor is the code editor that powers VS Code. A good page describing the code editor's features is here. It is licensed under the MIT License and supports Edge, Chrome, Firefox, Safari and Opera. The Monaco editor is not supported in mobile browsers or mobile web frameworks.


1 Answers

You can see the original TypeScript source for the java language defined at:

https://github.com/microsoft/monaco-languages/blob/master/src/java/java.ts

The Compiled JavaScript looks like:

Language

If you see, what you need is not part of the language as such but part of the config of that language.

So If I open the console window on the Monarch demo link and execute below

config = {"surroundingPairs":[{"open":"{","close":"}"}],"autoClosingPairs":[{"open":"{","close":"}"}],"brackets":[["{","}"]]}
monaco.languages.setLanguageConfiguration("monarch-language-mylang", config)

The auto-matching of brackets starts working as shown below

config

Matching works

So you need to make sure to set the config as well for your language

like image 162
Tarun Lalwani Avatar answered Sep 21 '22 10:09

Tarun Lalwani