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

Open
opened 2021-03-13 10:48:34 +01:00 by Irev-Dev · 2 comments
Irev-Dev commented 2021-03-13 10:48:34 +01:00 (Migrated from github.com)
No description provided.
Irev-Dev commented 2021-03-13 10:55:51 +01:00 (Migrated from github.com)

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.

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 2021-03-13 21:44:34 +01:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: h3n3/cadhub#247