Irev-Dev / cadhub

We're out to raise awareness and put CodeCAD on the map. The success of CadHub can be measured by the amount it promotes the use of CodeCAD within the mechanical/manufacturing industry and the strength the CadHub community.
https://cadhub.xyz
GNU General Public License v3.0
316 stars 59 forks source link

Add Monarch tokenization to Editor code pane for CascadeStudio and OpenSCAD. #247

Open Irev-Dev opened 3 years ago

Irev-Dev commented 3 years ago

I was in the mood to have a crack at this, and I didn't get very far, but I found a couple things that might be useful.

First of all I thought there might be a way to side step the Monarch tokenisation completely by using this textmate language file for openscad. https://github.com/tbuser/openscad.tmbundle/blob/master/Syntaxes/OpenSCAD.tmLanguage

However I've since learnt that tmLanguage files rely specifically on C regex of which the javascript regex is not compatible. There's this as a work around that leading the C regex in as a wasm file https://www.npmjs.com/package/monaco-editor-textmate But I wasn't super keen on adding another wasm file, also because the OpenSCAD language is pretty simple so implementing highlighting doesn't seem too crazy to me.

However I've not been able to find examples of folks defining languages with the react monaco-editor. So instead I was trying to use this as an example. https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages Trying to call the same functions in the beforeMount callback https://github.com/suren-atoyan/monaco-react#monaco-instance

But alas some dots mustn't be connected as I never got any highlighting to work.

Irev-Dev commented 3 years ago

I had missed the line monaco.languages.register({ id: 'openscad' }) 🤦 got something basic working but really only played with it. There's a lot to learn on how to match text for highlighting.

Some really cool things that we could do though, There's the hover provider example https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-hover-provider-example We could offer inline docs.