Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff server: Support .ipynb (Jupyter Notebook) files #10858

Closed
snowsignal opened this issue Apr 10, 2024 · 0 comments · Fixed by #11206
Closed

ruff server: Support .ipynb (Jupyter Notebook) files #10858

snowsignal opened this issue Apr 10, 2024 · 0 comments · Fixed by #11206
Assignees
Labels
server Related to the LSP server

Comments

@snowsignal
Copy link
Member

snowsignal commented Apr 10, 2024

ruff server needs to support .ipynb (aka Jupyter Notebook) files to have feature parity with ruff-lsp. In the LSP specification, these files are represented as notebook documents. Ruff can format and lint notebook documents, but their internal schema is different from the schema used by the LSP, so we'll need to convert between the two.

@snowsignal snowsignal added the server Related to the LSP server label Apr 10, 2024
@snowsignal snowsignal self-assigned this Apr 10, 2024
@snowsignal snowsignal added this to the Ruff Server: Beta milestone Apr 10, 2024
snowsignal added a commit that referenced this issue May 21, 2024
## Summary

Closes #10858.

`ruff server` now supports `*.ipynb` (aka Jupyter Notebook) files.
Extensive internal changes have been made to facilitate this, which I've
done some work to contextualize with documentation and an pre-review
that highlights notable sections of the code.

`*.ipynb` cells should behave similarly to `*.py` documents, with one
major exception. The format command `ruff.applyFormat` will only apply
to the currently selected notebook cell - if you want to format an
entire notebook document, use `Format Notebook` from the VS Code context
menu.

## Test Plan

The VS Code extension does not yet have Jupyter Notebook support
enabled, so you'll first need to enable it manually. To do this,
checkout the `pre-release` branch and modify `src/common/server.ts` as
follows:

Before:
![Screenshot 2024-05-13 at 10 59
06 PM](https://github.com/astral-sh/ruff/assets/19577865/c6a3c604-c405-4968-b8a2-5d670de89172)

After:
![Screenshot 2024-05-13 at 10 58
24 PM](https://github.com/astral-sh/ruff/assets/19577865/94ab2e3d-0609-448d-9c8c-cd07c69a513b)

I recommend testing this PR with large, complicated notebook files. I
used notebook files from [this popular
repository](https://github.com/jakevdp/PythonDataScienceHandbook/tree/master/notebooks)
in my preliminary testing.

The main thing to test is ensuring that notebook cells behave the same
as Python documents, besides the aforementioned issue with
`ruff.applyFormat`. You should also test adding and deleting cells (in
particular, deleting all the code cells and ensure that doesn't break
anything), changing the kind of a cell (i.e. from markup -> code or vice
versa), and creating a new notebook file from scratch. Finally, you
should also test that source actions work as expected (and across the
entire notebook).

Note: `ruff.applyAutofix` and `ruff.applyOrganizeImports` are currently
broken for notebook files, and I suspect it has something to do with
#11248. Once this is fixed, I
will update the test plan accordingly.

---------

Co-authored-by: nolan <nolan.king90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant