PRQL / prql-vscode

VS Code extension for PRQL lang
https://marketplace.visualstudio.com/items?itemName=PRQL-lang.prql-vscode
Apache License 2.0
24 stars 9 forks source link

Support syntax highlighting in Jupyter nodebooks #661

Open jest opened 3 weeks ago

jest commented 3 weeks ago

I use VSCode with this extension to write PRQL files, as well as to develop and run Jupyter notebooks with Microsoft's Jupyter extension (https://github.com/Microsoft/vscode-jupyter.git) against kernel with pyprql.

I noticed that although syntax highlighting works fine for *.prql files, there is no option to set the PRQL language for individual cells in the notebook:

image

Is it possible to use syntax highlighting provided for "normal" editors to support highlighting in the Jupyter cells?

jest commented 3 weeks ago

Digging a bit deeper, I found this:

https://github.com/microsoft/vscode/blob/756f4313e279815f5d2420ff88af880c78a86a3d/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts#L431

let languages = context.notebookEditor.activeKernel?.supportedLanguages;

So it looks like the list of supported languages is taken from the active kernel, and pyprql does not advertise itself.

max-sixty commented 3 weeks ago

Yes I'd really like this to work!

Digging a bit deeper, I found this:

Thanks for looking into it. Does that mean this is much easier than getting it to work in Jupyter normal? There are some notes from https://github.com/PRQL/pyprql/issues/45 — last time I checked it was speculative whether it was even possible.

Do you know how autodetect works there?

(We would definitely take any PR that contributed towards this, would be a v nice improvement)

jest commented 2 weeks ago

Following with short analysis and debugging of the editActions.ts mentioned above, to my surprise the cell language selectio process looks completely different when there is no active kernel.

In such a case, the list of languages presented to the user for the given cell is the "normal" list of languages supported by VSCode, including PRQL! After choosing PRQL, syntax highlighting and error reporting works nice within the cell:

image

Unfortunatelly, after connecting the notebook to a Jupyter server, the list of available kernel languages is fetched from there and the cell language changes automatically from PRQL to Python.

So at the first sight it looks like the user-facing functions of VSCode+prql-vscode work well within cells. At the moment I don't know to what extent those functions implementations are instead provided by the attached kernel, so further checks with pyprql installed in Jupyter kernel are needed.

max-sixty commented 1 week ago

(thanks a lot for looking into that, that makes sense... So I guess fixing https://github.com/PRQL/pyprql/issues/45 would fix this too... )