ruff/crates/ruff_server
Brent Westbrook 9925910a29
Add a ViolationMetadata::rule method (#18234)
Summary
--

This PR adds a macro-generated method to retrieve the `Rule` associated
with a given `Violation` struct, which makes it substantially cheaper
than parsing from the rule name. The rule is then converted to a
`NoqaCode` for storage on the `Message` (and eventually on the new
diagnostic type). The `ViolationMetadata::rule_name` method was now
unused, so the `rule` method replaces it.

Several types had to be moved from the `ruff_diagnostics` crate to the
`ruff_linter` crate to make this work, namely the `Violation` traits and
the old `Diagnostic` type, which had a constructor generic over a
`Violation`.

It's actually a fairly small PR, minus the hundreds of import changes.
The main changes are in these files:

-
[crates/ruff_linter/src/message/mod.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-139754ea310d75f28307008d21c771a190038bd106efe3b9267cc2d6c0fa0921)
-
[crates/ruff_diagnostics/src/lib.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-8e8ea5c586935bf21ea439f24253fcfd5955d2cb130f5377c2fa7bfee3ea3a81)
-
[crates/ruff_linter/src/diagnostic.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-1d0c9aad90d8f9446079c5be5f284150d97797158715bd9729e6f1f70246297a)
-
[crates/ruff_linter/src/lib.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-eb93ef7e78a612f5fa9145412c75cf6b1a5cefba1c2233e4a11a880a1ce1fbcc)

Test Plan
--

Existing tests
2025-05-28 09:27:09 -04:00
..
assets Update documentation for ruff server with new migration guide (#11499) 2024-05-22 14:36:33 -07:00
docs Add docs for Ruff language server (#12344) 2024-07-18 17:41:43 +05:30
resources/test/fixtures Expand ruff.configuration to allow inline config (#16296) 2025-02-26 10:17:11 +05:30
src Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
Cargo.toml Fallback to requires-python in certain cases when target-version is not found (#16721) 2025-03-14 09:36:51 +01: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 docs for Ruff language server (#12344) 2024-07-18 17:41:43 +05:30

The Ruff Language Server

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.

Refer to the documentation for more information on how to set up the language server with your editor and configure it to your liking.

Contributing

Contributions are welcome and highly appreciated. To get started, check out the contributing guidelines.

You can also join us on Discord.