Using Monaco editor - monaco branch now in fork (PR#2971)

Hi Nick, thanks for chiming in & casting an eye over.

I did mean on a users local clone - not the real deal haha (note to self, be more explicit :slight_smile: )


I'm not certain if you have looked at the implementation but this is the approach I took.
In the settings file, you have to set the editor to "monaco" to use it.


One thing that might wish to be considered leading to this (or any other editor for that matter) is to abstract the ACE interface and discipline ourselves NOT to call anything other than the functions offered in editor.js - that would make any editor more of a drop in replacement instead of shimming the ACE functions (not quite a plugin - but approaching that level of integration).

So, how could we proceed Nick?

Shall I raise a PR for discussion? I am certain there are better ways to achieve the integration than what I have done (I just dont know core as well as you guys) so there will be some leg work - and i know your time is tight (mine too) - but it would be a shame to not explore this?

Let me know either way. Cheers.

The only way to get me to look and review code is a PR. That then gets it somewhere where it can be put into a plan and prioritised against everything else.

Just chiming in to encourage you to submit this PR at your earliest convenience :slight_smile:

I'm working on a (phenomenally talented) team that doesn't have much experience writing enterprise-level software outside of myself, and an improved editing environment would be extremely helpful. We're building a fairly complex system, and even just auto-formatting on save (let alone everything else) would make the change worth it. The ACE editor truly leaves a lot to be desired...

Really impressed by the effort here!

4 Likes

This would be a very welcome upgrade from ACE

@csml, @emes, I will soon. Just a bit busy right now. Thanks for the nudge.

1 Like

I have already seen the monaco editor in action in other projects and can hardly wait for a possibility to use it regularly in Node-red.

1 Like

Hi all, I have updated my fork to latest monaco editor V0.21.2 (released 2 days ago)

I have pulled latest node-red from github and merged that into this repo.

I had to make some extensive changes to how it integrates due to issues with the AMD loader it uses.

I ended up compiling the ESM code using parcel and adding it manually to avoid the dreaded Uncaught Error: Can only have one anonymous define call per script file

I will try to get a PR raised soon.

In the mean time, I would appreciate it if anyone wants to evaluate - would give me confidence to raise PR...

git clone https://github.com/Steve-Mcl/node-red.git
cd node-red
git checkout monaco
npm install
npm run build
npm start

then edit your settings.js - add this ...

editor: {
        lib: "MONACO", //can be "MONACO" or "ACE"
        options: {
            /* theme - must match the file name of a theme in 
             * packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
             * e.g. "tomorrow-night", "upstream-sunburst", "github", "my-own-lushtastic-theme"
             */
            theme: "birds-of-paradise",
            minimap: {
                enabled: true,
                maxColumn: 30,
                scale: 1,
                showSlider : "mouseover",
                renderCharacters: true
            },
            fontSize: 11
        }
    }
6 Likes

Works for me. Would love to see a PR

2 Likes

Another update pushed to repo (and recent changes in upstream merged into the monaco branch) - in short, this fork is in-line with latest node-red source & the monaco branch is in-line with the dev branch (v1.2.0 as of writing)

Progress...

  • Fixed: hover tips clipped by the container DIV

  • Finally got JSONata colourisation, tooltips and snippets going (this was the last major feature point)...

  • Also plays nicely with es2020 nullish coalescing operator & optional chaining
    image

  • and common language tooltips / intellisense...
    image

Issues...

  • Monacos' context menu & hover tips are still clipped by the side-bar - regardless of z-index - cant figure this one out. Not a show stopper and could release with a "known issue"

Otherwise - looking good.

  • No errors in console
  • All contrib nodes (that i have installed) work without modification
    • I haven't installed every contrib node that might use the ACE editor but I have tested ui_builder, template, ui_template, function, unsafe function, mssql, json

h-e-l-p

I would appreciate it someone would be willing to download / test / feedback on...

  • mac
  • linux
  • ios?
  • andoid?

... to give me confidence to (finally) raise a PR.

Install instructions are in above post (and in post #1) but if you need help, gimmie a shout

3 Likes

Works fine on mac.

On linux, I'm getting an uglify error during 'npm run build':

Running "uglify:build" (uglify) task
JS_Parse_Error [SyntaxError]: Unexpected token: punc «.»
    at JS_Parse_Error.get (eval at <anonymous> (/home/ms/nrtest/node-red/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:71:23)
    at formatError (internal/util/inspect.js:1179:38)
    at formatRaw (internal/util/inspect.js:949:14)
    at formatValue (internal/util/inspect.js:803:10)
    at inspect (internal/util/inspect.js:336:10)
    at formatWithOptionsInternal (internal/util/inspect.js:2006:40)
    at formatWithOptions (internal/util/inspect.js:1888:10)
    at console.value (internal/console/constructor.js:313:14)
    at console.log (internal/console/constructor.js:348:61)
    at /home/ms/nrtest/node-red/node_modules/grunt-contrib-uglify/tasks/uglify.js:144:17 {
  filename: 'red.js',
  line: 29249,
  col: 95,
  pos: 1244282
}
>> Uglifying source packages/node_modules/@node-red/editor-client/public/red/red.js failed.
Warning: Uglification failed.
Unexpected token: punc «.». 
Line 29249 in packages/node_modules/@node-red/editor-client/public/red/red.js
 Use --force to continue.
2 Likes

Hi Michael (@emes)

Thank you for testing on macos and linux - it is appreciated.

I believe the issue was es6 syntax (... spread operator) tripping up your linux build (thats where line 29249 took me).

I have gone through the monaco code additions and reined in the es6.

1 Like

A bit of a feature demo - ligatures :slight_smile:

v6AIlmz4JC

If you have a font with ligatures you can enable ligatures in the settings...

settings.js (obviously, only valid for monaco branch of this fork)...

    editor: {
        lib: "MONACO", //can be "MONACO" or "ACE"
        //  lib: "ACE", //can be "MONACO" or "ACE"
        options: {
            /* theme - must match the file name of a theme in 
             * packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
             * e.g. "tomorrow-night", "upstream-sunburst", "github", "my-own-lushtastic-theme"
             */
            theme: "tomorrow",
            minimap: {
                enabled: true,
                maxColumn: 40,
                scale: 1,
                showSlider : "mouseover",
                renderCharacters: true
            },
            fontSize: 14,
            fontLigatures: true,
            fontFamily: "Cascadia Code, Fira Code, Consolas, 'Courier New', monospace",
            fontWeight: "300"
        }
    }

fonts Cascadia, Fira

2 Likes

Never understood why programmers want ligatures myself. It hides the actual characters which are core to the syntax. Always feels like there could be a danger of getting a wrong character that would be almost impossible to debug. Of course, that could just be my natural paranoia or a reflection of my own poor programming skills.

3 Likes

I am personally on the fence.

Some folk really love em so I guess I just wanted to demonstrate the possibility for folks who must have them.

2 Likes

I've been using Fira Code with ligatures for 2-3 years now. I would say there's no going back after you get used to them. I just recently went through the trouble to switch and reconfigure a new terminal app for Linux partly due to ligature support. :grin:

I think they rather make you certain you typed the correct characters as otherwise the the characters wouldn't snap together in a satisfying way. :slightly_smiling_face:.

But I'm also a lot into code aesthetics and nowadays ligatures are part of if it.

Well, I'm rather OCD about code layout but conversely I date from those heady times when getting to work on a 4-colour text terminal on the mainframe meant that you were a VIP user :smiley:

In fact (off topic), I was instrumental in creating a set of "gui" overlays for the IBM ISPF terminal "personal computing" system to implement IBM's Common User Access gui on 3270 text terminals. IBM told us it couldn't be done, so we went and did it anyway. It was a cheat of course in that you had to craft lots of individual screens that you swapped between. It was good though and I built some really useful business apps using it.

1 Like

Hi all, been progressing monaco implementation.

Progress...

  • Added @types for node and node-red
  • Deleted all the DOM stuff from intellisense
  • improved snippets
  • improved JSONata
  • error checking

If anyone is still reading - would you mind?

I have a quick test below. I would love it if you could take a glance, see how many errors you spot? I deliberately haven't posted the code (so less chance of cheating)
You will not be judged - I am genuinely interested in your answers. I have made several of the errors myself in my time with node-red...

If anyone is still reading - results...

A few hours ago, in the previous post, I asked how many errors did you see in the screenshot.

Some were easy, some were a bit more knowledge based, others were downright devious :slight_smile:


There were 10 issues / errors - here is a demo of what monaco editor can do...

(click me to reveal)



Thoughts

While it may not be beneficial to have such strict error checking on by default, individual issues can be easily quietened by adding // @ts-ignore above the item

image

And if you wish, the whole file in one go...
KyXTi45AB0

alternatively, the JS checking option could be toggled by a node option e.g... Check JavaScript


All of these improvements are now pushed to my fork (see first post for info)

4 Likes

I want it! When can we have it in Node-RED main branch :pray:

1 Like

See previous comments from Nick above.