ruff/crates/ruff_server
Jane Lewis 35ca887e02
ruff server: Ruff configuration from client settings overrides project configuration (#11062)
## Summary

This is a follow-up to https://github.com/astral-sh/ruff/pull/10984 that
implements configuration resolution for editor configuration. By 'editor
configuration', I'm referring to the client settings that correspond to
Ruff configuration/options, like `preview`, `select`, and so on. These
will be combined with 'project configuration' (configuration taken from
project files such as `pyproject.toml`) to generate the final linter and
formatter settings used by `RuffSettings`. Editor configuration takes
priority over project configuration.

In a follow-up pull request, I'll implement a new client setting that
allows project configuration to override editor configuration, as per
[this issue](https://github.com/astral-sh/ruff-vscode/issues/425).

## Review guide

The first commit, e38966d8843becc7234fa7d46009c16af4ba41e9, is just
doing re-arrangement so that we can pass the right things to
`RuffSettings::resolve`. The actual resolution logic is in the second
commit, 0eec9ee75c10e5ec423bd9f5ce1764f4d7a5ad86. It might help to look
at these comments individually since the diff is rather messy.

## Test Plan

For the settings to show up in VS Code, you'll need to checkout this
branch: https://github.com/astral-sh/ruff-vscode/pull/456.

To test that the resolution for a specific setting works as expected,
run through the following scenarios, setting it in project and editor
configuration as needed:

| Set in project configuration? | Set in editor configuration? |
Expected Outcome |

|-------------------------------|--------------------------------------------------|------------------------------------------------------------------------------------------|
| No | No | The editor should behave as if the setting was set to its
default value. |
| Yes | No | The editor should behave as if the setting was set to the
value in project configuration. |
| No | Yes | The editor should behave as if the setting was set to the
value in editor configuration. |
| Yes | Yes (but distinctive from project configuration) | The editor
should behave as if the setting was set to the value in editor
configuration. |

An exception to this is `extendSelect`, which does not have an analog in
TOML configuration. Instead, you should verify that `extendSelect`
amends the `select` setting. If `select` is set in both editor and
project configuration, `extendSelect` will only append to the `select`
value in editor configuration, so make sure to un-set it there if you're
testing `extendSelect` with `select` in project configuration.
2024-04-23 11:19:17 -07:00
..
docs/setup ruff server: fix Neovim setup guide command (#11021) 2024-04-19 08:24:09 +05:30
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: Ruff configuration from client settings overrides project configuration (#11062) 2024-04-23 11:19:17 -07:00
tests ruff server - A new built-in LSP for Ruff, written in Rust (#10158) 2024-03-08 20:57:23 -08:00
Cargo.toml ruff server: Resolve configuration for each document individually (#10950) 2024-04-16 18:15:02 +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.