PRQL / pyprql

Python extensions for PRQL
https://pyprql.readthedocs.io
Apache License 2.0
92 stars 4 forks source link

Jupyter syntax highlighting #45

Open max-sixty opened 2 years ago

max-sixty commented 2 years ago

As a follow-up to #44, I wonder whether it's possible to get syntax highlighting in the jupyter cells.

Currently it inherits from python:

image

There's a discussion here on this, which links to https://github.com/jupyter-lsp/jupyterlab-lsp/pull/553, which looks good, and not too involved, to get %%bigquery working. They have the advantage that there's already available syntax for SQL. I would hope that we could reuse one of our many existing definitions, but I've said that a few times before about syntax definitions :)

rbpatt2019 commented 2 years ago

Perhaps it's just too early and I need more coffee, but the above approach isn't twigging for me. Do we need a separate typescript plugin to handle this?

max-sixty commented 2 years ago

Yes, unfortunately I think this will be in typescript. And I'm also not sure how the typescript file is linked to (does it rely on other code in jupyterlab-lsp??)...

max-sixty commented 1 year ago

I think this would be great to do, I may give this a swing soon. Unfortunately it involve JS, my great weakness...

Another reference: https://twitter.com/Mbussonn/status/636626829269442562 from @Carreau, suggests it should be possible.

And https://github.com/catherinedevlin/ipython-sql/issues/85

max-sixty commented 1 year ago

OK, this is a bigger project than I imagined. Here's the thread for Stan: https://github.com/jupyterlab/jupyterlab/issues/5504. So it's possible, but not easy, and hardly documented.

(and that's for jupyterlab, it's not completely clear that would work for the notebook. And it might be really hard for Colab: https://github.com/googlecolab/colabtools/issues/2039)

It looks like it depends on at least https://github.com/prql/prql/issues/1102

It's a shame this is difficult — this could be a first-class PRQL experience — and under our control, rather than relying on another tool. Without syntax highlighting, it's going to be difficult to build the momentum to add auto-complete / LSP / etc here.

So if anyone would be up for making some contributions here — e.g. the Lezer grammar, or a better understanding of what's required overall — that would be very welcome.

max-sixty commented 1 year ago

The Lezer grammar is coming along (thanks to @vanillajonathan ) — including packaging & tests.

So I'll take another look at doing this, despite my very poor JS. (unless anyone else would like to take a swing...)

Here is the JupySQL version, which has recently been added: https://github.com/ploomber/jupysql-plugin/blob/1e058e7f93d3085b7a7c0eab4f5c4864000b44eb/src/editor/editor.ts

And another, from a while ago: https://github.com/WardBrian/jupyterlab-stan-highlight/blob/master/lib/stan.js