Apex syntax highlighting?

Hello Theia team!

I was wondering if there’s a way to turn on syntax highlighting for “apex” code? I see that it’s bundled with the Monaco now. Looks like as of version 0.14.0.

Top of the list in the example editor:


Is there a process I need to follow to get that switched on in my local version of Theia?

Thanks for any info on this!

[original thread by Ricardo Viera]

hello, most of syntaxes are there:https://github.com/theia-ide/theia/tree/master/packages/textmate-grammars/data. So by adding json file and registering it, it would bring the support

Also right now, we’re bringing support for VS code extension so I would just use https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-apex which is bringing syntax highlight

[Nick Chen]

Could you clarify how Theia works with grammars? As far as I know from https://github.com/Microsoft/monaco-editor/blob/master/README.md#faq the monaco code editor doesn’t work with textmate grammars out of the box because of the regex engine requirement, which is based on oniguruma. Thus, the monaco editor requires using new grammars written in the Monarch syntax.

However, the link that you provided (https://github.com/theia-ide/theia/tree/master/packages/textmate-grammars/data) and also the mention of just using the salesforcedx-vscode-apex extension implies that Theia somehow supports textmate grammars out of the box.

Could you shed some light on how it does this? Does this imply that Theia’s syntax highlighting is more resource intensive since it’s no longer completely rendered through the browser using JavaScript regex but requires a backend?

[Nick Chen]

Maybe I found the answer to my question:

Theia is using onigasm (https://www.npmjs.com/package/onigasm) as linked from https://github.com/theia-ide/theia/blob/master/packages/monaco/package.json#L16

And on the main page of onigasm, it states:

“Of course, unlike node-oniguruma, this library can’t hook into roots of V8 and is therefore 2 times* slower than the former.”

So, it’s likely that syntax highlighting in Theia today is potentially up to twice as slow as just using monaco Monarch grammars. I guess that is the engineering trade-off that Theia is making for reuse of the large availability of Textmate grammars.