ruff/crates/ruff_server
Dhruv Manilawala 7910beecc4
Consider the content of the new cells during notebook sync (#12203)
## Summary

This PR fixes the bug where the server was not considering the
`cells.structure.didOpen` field to sync up the new content of the newly
added cells.

The parameters corresponding to this request provides two fields to get
the newly added cells:
1. `cells.structure.array.cells`: This is a list of `NotebookCell` which
doesn't contain any cell content. The only useful information from this
array is the cell kind and the cell document URI which we use to
initialize the new cell in the index.
2. `cells.structure.didOpen`: This is a list of `TextDocumentItem` which
corresponds to the newly added cells. This actually contains the text
content and the version.

This wasn't a problem before because we initialize the cell with an
empty string and this isn't a problem when someone just creates an empty
cell. But, when someone copy-pastes a cell, the cell needs to be
initialized with the content.

fixes: #12201 

## Test Plan

First, let's see the panic in action:

1. Press <kbd>Esc</kbd> to allow using the keyboard to perform cell
actions (move around, copy, paste, etc.)
2. Copy the second cell with <kbd>c</kbd> key
3. Delete the second cell with <kbd>dd</kbd> key
4. Paste the copied cell with <kbd>p</kbd> key

You can see that the content isn't synced up because the `unused-import`
for `sys` is still being highlighted but it's being used in the second
cell. And, the hover isn't working either. Then, as I start editing the
second cell, it panics.


fc58364c-c8fc-4c11-a917-71b6dd90c1ef

Now, here's the preview of the fixed version:


207872dd-dca6-49ee-8b6e-80435c7ef22e
2024-07-05 17:10:00 +05:30
..
assets Update documentation for ruff server with new migration guide (#11499) 2024-05-22 14:36:33 -07:00
docs ruff server: Support the usage of tildes and environment variables in logFile (#11945) 2024-06-20 18:51:46 +00:00
resources/test/fixtures Add Jupyter Notebook document change snapshot test (#11944) 2024-06-21 05:29:27 +00:00
src Consider the content of the new cells during notebook sync (#12203) 2024-07-05 17:10:00 +05:30
tests Remove usage of std::path::absolute from snapshot test (#11973) 2024-06-21 20:21:12 +01:00
Cargo.toml ruff server: Tracing system now respects log level and trace level, with options to log to a file (#11747) 2024-06-11 11:29:47 -07:00
CONTRIBUTING.md High-level project overview and contributing guide for ruff server (#10565) 2024-03-25 23:08:37 -07:00
README.md Add Vim and Kate setup guide for ruff server (#11615) 2024-05-31 19:06:55 +00:00

The Ruff Language Server

Welcome!

ruff server is a language server that powers Ruff's editor integrations.

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 construct 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.

If you're transferring your configuration from ruff-lsp, regardless of editor, there are several settings which have changed or are no longer available. See the migration guide for more.

VS Code

Install the Ruff extension from the VS Code Marketplace.

As this server is still in Beta, you will need to enable the "Native Server" extension setting, either in the settings UI:

A screenshot showing an enabled "Native Server" extension setting in the VS Code settings view

Or in your settings.json:

{
  "ruff.nativeServer": true
}

From there, you can configure Ruff to format Python code on-save with:

{
  "[python]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "charliermarsh.ruff"
  }
}

For more, see Configuring VS Code in the Ruff extension documentation.

By default, the extension will run against the ruff binary that it discovers in your environment. If you don't have ruff installed, the extension will fall back to a bundled version of the binary.

Neovim

See the Neovim setup guide.

Helix

See the Helix setup guide.

Vim

See the Vim setup guide.

Kate

See the Kate 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 Discord if you have questions.