PRQL / prql

PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement
https://prql-lang.org
Apache License 2.0
9.97k stars 218 forks source link

Use CodeMirror for the playground? #3598

Open max-sixty opened 1 year ago

max-sixty commented 1 year ago

What's up?

Replacing Monaco for CodeMirror 6 would let us use the Lezer grammar that @vanillajonathan has done a lot of work on. The Monarch grammar that Monaco uses has some mistakes, and requires maintenance that we could avoid.

In addition, here are a couple of blog posts extolling the benefits of CodeMirror 6 over Monaco.

For completeness — this would be some non-trivial JS work, and isn't a top priority. But it would be a nice, self-contained contribution.

vanillajonathan commented 1 year ago

I now see that the playground uses its own syntax highlighting, I would have thought it would use the same one as in the vscode extension since they both use Monaco?

Yes, I've done a lot of work on the Lezer grammar but I don't know if it is any better or worse. It still needs more work. Other grammars are dumb so they're easy to write, it's just a bunch of regular expressions, but Lezer is different, its like eBNF or aBNF, it wants to know the context of which the tokens appear in, so it's trickier.

I am sure both Monaco and CodeMirror are great, and I am sure both will continue to improve. Microsoft is surely going to improve Monaco. Reading the above mentioned blogs I am not sure those arguments apply much to our playground; their perceived problems with Monaco and advantages of CodeMirror doesn't apply much to us.

I do think we should setup a demo of CodeMirror with our PRQL lezer grammar though. Then we can iron out any eventual issues that might we come across, and perhaps later migrate to CodeMirror for the playground.

I think either Monaco or CodeMirror would be great for us, but I don't think it makes much of a difference which one we use.

max-sixty commented 1 year ago

I now see that the playground uses its own syntax highlighting, I would have thought it would use the same one as in the vscode extension since they both use Monaco?

I had the same expectation! But they use different syntax highlighting approaches! 🤷

Reading the above mentioned blogs I am not sure those arguments apply much to our playground; their perceived problems with Monaco and advantages of CodeMirror doesn't apply much to us. I think either Monaco or CodeMirror would be great for us, but I don't think it makes much of a difference which one we use.

Yes, I think you're 100% correct.

The main advantage in my mind was to use your syntax highlighting work.

I do think we should setup a demo of CodeMirror with our PRQL lezer grammar though.

Yes, my plan was to use this for a Jupyter Extension, which would be a great win for the project. (contributions welcome! Though it is a difficult ambiguous project...)

Ofc if it's easy to get a demo working with a plain CodeMirror 6 editor then that'd be a good test of the highlighting

not-my-profile commented 1 year ago

While I haven't yet integrated Monaco anywhere, I can vouch for CodeMirror. It's well documented, incredibly extensible and Marijn is doing a phantastic job at maintaining it, quickly resolving issues on GitHub as well as answering questions on https://discuss.codemirror.net/. The project is a joy to use and interact with.

(Sidenote: I'm currently very busy with a project of my own ... I'm just keeping an occasional side-eye on the issues here.)

vanillajonathan commented 1 year ago

I created a PR (#3608) with a demo using CodeMirror with our Lezer grammar.