ruff/crates/ruff_server
Jane Lewis b0731ef9cb
ruff server: Support Jupyter Notebook (*.ipynb) files (#11206)
## Summary

Closes https://github.com/astral-sh/ruff/issues/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](c6a3c604-c405-4968-b8a2-5d670de89172)

After:
![Screenshot 2024-05-13 at 10 58
24 PM](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
https://github.com/astral-sh/ruff/issues/11248. Once this is fixed, I
will update the test plan accordingly.

---------

Co-authored-by: nolan <nolan.king90@gmail.com>
2024-05-21 22:29:30 +00:00
..
docs/setup Write ruff server setup guide for Helix (#11183) 2024-04-30 10:15:29 -07:00
resources/test/fixtures ruff server: Introduce settings for directly configuring the linter and formatter (#10984) 2024-04-18 07:53:48 +00:00
src ruff server: Support Jupyter Notebook (*.ipynb) files (#11206) 2024-05-21 22:29:30 +00:00
tests ruff server: Support Jupyter Notebook (*.ipynb) files (#11206) 2024-05-21 22:29:30 +00:00
Cargo.toml ruff server: Support Jupyter Notebook (*.ipynb) files (#11206) 2024-05-21 22:29:30 +00:00
CONTRIBUTING.md High-level project overview and contributing guide for ruff server (#10565) 2024-03-25 23:08:37 -07:00
README.md ruff server: Write a setup guide for Neovim (#10987) 2024-04-18 02:46:30 +00:00

The Ruff Language Server

Welcome! ruff server is a language server that powers editor integrations with Ruff. The job of the language server is to listen for requests from the client, (in this case, the code editor of your choice) and call into Ruff's linter and formatter crates to create real-time diagnostics or formatted code, which is then sent back to the client. It also tracks configuration files in your editor's workspace, and will refresh its in-memory configuration whenever those files are modified.

Setup

We have specific setup instructions depending on your editor. If you don't see your editor on this list and would like a setup guide, please open an issue.

  • Visual Studio Code: Install the Ruff extension from the VS Code Marketplace. The language server used by the extension will be, by default, the one in your actively-installed ruff binary. If you don't have ruff installed and haven't provided a path to the extension, it comes with a bundled ruff version that it will use instead. Since the new Ruff language server has not yet been stabilized, you will need to use the pre-release version of the extension and enable the Experimental Server setting.
  • Neovim: See the Neovim setup guide.

Contributing

If you're interested in contributing to ruff server - well, first of all, thank you! Second of all, you might find the contribution guide to be a useful resource. Finally, don't hesitate to reach out on our Discord if you have questions.