Search code examples
monaco-editorreact-monaco-editor

Can I set Monaco Editor to highlight errors in C code?


I'm using Monaco Editor in a React app, instantiating it like this:

<Editor
 height="70vh"
 defaultLanguage="C"
 value={myCode}
 onChange={handleChange}
/>

If I set "defaultLanguage" to "javascript" then it validates whatever I type in and it highlights anything that's not proper javaScript in red. However, I want to be able to validate C code, but when I change defaultLanguage to "C" it doesn't highlight any errors. It still allows me to hit CTRL-space to see suggestions etc, but if I type in nonsense it doesn't highlight it.

Am I doing something wrong?


Solution

  • Monaco comes with a number of languages that have base support and a couple of them with full support. Javascript, Typescript, CSS, HTML and JSON belong to the second category. Check the node module folder monaco-editor/esm/vs which has a folder basic-languages and a folder language. The basic language support only comprises syntax highlighting. For more functionality you have to write an own parser and handle editor content change by that. Though this is a pretty big topic, not well suited for a single Q&A post.