![]() ## Summary This PR fixes various bugs for computing the replacement range between the original and modified source for the language server. 1. When finding the end offset of the source and modified range, we should apply `zip` on the reversed iterator. The bug was that it was reversing the already zipped iterator. The problem here is that the length of both slices aren't going to be the same unless the source wasn't modified at all. Refer to the [Rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=44f860d31bd26456f3586b6ab530c22f) where you can see this in action. 2. Skip the first line when computing the start offset because the first line start value will always be 0 and the default value of the source / modified range start is also 0. So, comparing 0 and 0 is not useful which means we can skip the first value. 3. While iterating in the reverse direction, we should only stop if the line start is strictly less than the source start i.e., we should use `<` instead of `<=`. fixes: #12128 ## Test Plan Add test cases where the text is being inserted, deleted, and replaced between the original and new source code, validate the replacement ranges. |
||
---|---|---|
.. | ||
assets | ||
docs | ||
resources/test/fixtures | ||
src | ||
tests | ||
Cargo.toml | ||
CONTRIBUTING.md | ||
README.md |
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:
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.