Skip to content

Commit f19cb86

Browse files
authored
Update migration guide with the new ruff.configuration (#16567)
## Summary This PR updates the migration guide to use the new `ruff.configuration` settings update to provide a better experience. ### Preview <details><summary>Migration page screenshot</summary> <p> ![Ruff Editors Migration](https://github.com/user-attachments/assets/38062dbc-a4c5-44f1-8dba-53f7f5872d77) </p> </details>
1 parent 36d12ce commit f19cb86

File tree

1 file changed

+98
-41
lines changed

1 file changed

+98
-41
lines changed

docs/editors/migration.md

Lines changed: 98 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
# Migrating from `ruff-lsp`
22

3-
To provide some context, [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) is the LSP implementation for Ruff to power the editor
4-
integrations which is written in Python and is a separate package from Ruff itself. The **native
5-
server** is the LSP implementation which is written in Rust and is available under the `ruff server`
6-
command. This guide is intended to help users migrate from
7-
[`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) to the native server.
3+
[`ruff-lsp`][ruff-lsp] is the [Language Server Protocol] implementation for Ruff to power the editor
4+
integrations. It is written in Python and is a separate package from Ruff itself. The **native
5+
server**, however, is the [Language Server Protocol] implementation which is **written in Rust** and
6+
is available under the `ruff server` command. This guide is intended to help users migrate from
7+
[`ruff-lsp`][ruff-lsp] to the native server.
88

99
!!! note
1010

11-
The native server was first introduced in Ruff version `0.3.5`. It was marked as beta in version
12-
`0.4.5` and officially stabilized in version `0.5.3`. It is recommended to use the latest
13-
version of Ruff to ensure the best experience.
11+
The native server was first introduced in Ruff version `0.3.5`. It was marked as [beta in
12+
version `0.4.5`](https://astral.sh/blog/ruff-v0.4.5) and officially [stabilized in version
13+
`0.5.3`](https://github.com/astral-sh/ruff/releases/tag/0.5.3). It is recommended to use the
14+
latest version of Ruff to ensure the best experience.
1415

1516
The migration process involves any or all of the following:
1617

1718
1. Migrate [deprecated settings](#unsupported-settings) to the [new settings](#new-settings)
1819
1. [Remove settings](#removed-settings) that are no longer supported
1920
1. Update the `ruff` version
2021

22+
Read on to learn more about the unsupported or new settings, or jump to the [examples](#examples)
23+
that enumerate some of the common settings and how to migrate them.
24+
2125
## Unsupported Settings
2226

23-
The following [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) settings are not supported by `ruff server`:
27+
The following [`ruff-lsp`][ruff-lsp] settings are not supported by the native server:
2428

25-
- `lint.run`: This setting is no longer relevant for the native language server, which runs on every
26-
keystroke by default.
27-
- `lint.args`, `format.args`: These settings have been replaced by more granular settings in `ruff server` like [`lint.select`](settings.md#select), [`format.preview`](settings.md#format_preview),
28-
etc. along with the ability to provide a default configuration file using [`configuration`](settings.md#configuration).
29+
- [`lint.run`](settings.md#lintrun): This setting is no longer relevant for the native language
30+
server, which runs on every keystroke by default.
31+
- [`lint.args`](settings.md#lintargs), [`format.args`](settings.md#formatargs): These settings have
32+
been replaced by more granular settings in the native server like [`lint.select`](settings.md#select),
33+
[`format.preview`](settings.md#format_preview), etc. along with the ability to override any
34+
configuration using the [`configuration`](settings.md#configuration) setting.
2935

30-
The following settings are not accepted by the language server but are still used by the VS Code
31-
extension. Refer to their respective documentation for more information on how it's being used by
32-
the extension:
36+
The following settings are not accepted by the language server but are still used by the [VS Code extension].
37+
Refer to their respective documentation for more information on how each is used by the extension:
3338

3439
- [`path`](settings.md#path)
3540
- [`interpreter`](settings.md#interpreter)
3641

3742
## Removed Settings
3843

39-
Additionally, the following settings are not supported by the native server, they should be removed:
44+
Additionally, the following settings are not supported by the native server and should be removed:
4045

41-
- `ignoreStandardLibrary`
42-
- `showNotifications`
46+
- [`ignoreStandardLibrary`](settings.md#ignorestandardlibrary)
47+
- [`showNotifications`](settings.md#shownotifications)
4348

4449
## New Settings
4550

46-
`ruff server` introduces several new settings that [`ruff-lsp`](https://github.com/astral-sh/ruff-lsp) does not have. These are, as follows:
51+
The native server introduces several new settings that [`ruff-lsp`][ruff-lsp] does not have:
4752

4853
- [`configuration`](settings.md#configuration)
4954
- [`configurationPreference`](settings.md#configurationpreference)
@@ -55,44 +60,96 @@ Additionally, the following settings are not supported by the native server, the
5560
- [`lint.ignore`](settings.md#ignore)
5661
- [`lint.preview`](settings.md#lint_preview)
5762

58-
Several of these new settings are replacements for the now-unsupported `format.args` and `lint.args`. For example, if
59-
you've been passing `--select=<RULES>` to `lint.args`, you can migrate to the new server by using `lint.select` with a
60-
value of `["<RULES>"]`.
61-
6263
## Examples
6364

64-
Let's say you have these settings in VS Code:
65+
All of the examples mentioned below are only valid for the [VS Code extension]. For other editors,
66+
please refer to their respective documentation sections in the [settings](settings.md) page.
67+
68+
### Configuration file
69+
70+
If you've been providing a configuration file as shown below:
6571

6672
```json
6773
{
68-
"ruff.lint.args": "--select=E,F --line-length 80 --config ~/.config/custom_ruff_config.toml"
74+
"ruff.lint.args": "--config ~/.config/custom_ruff_config.toml",
75+
"ruff.format.args": "--config ~/.config/custom_ruff_config.toml"
6976
}
7077
```
7178

72-
After enabling the native server, you can migrate your settings like so:
79+
You can migrate to the new server by using the [`configuration`](settings.md#configuration) setting
80+
like below which will apply the configuration to both the linter and the formatter:
7381

7482
```json
7583
{
76-
"ruff.configuration": "~/.config/custom_ruff_config.toml",
77-
"ruff.lineLength": 80,
78-
"ruff.lint.select": ["E", "F"]
84+
"ruff.configuration": "~/.config/custom_ruff_config.toml"
7985
}
8086
```
8187

82-
Similarly, let's say you have these settings in Helix:
88+
### `lint.args`
8389

84-
```toml
85-
[language-server.ruff.config.lint]
86-
args = "--select=E,F --line-length 80 --config ~/.config/custom_ruff_config.toml"
90+
If you're providing the linter flags by using `ruff.lint.args` like so:
91+
92+
```json
93+
{
94+
"ruff.lint.args": "--select=E,F --unfixable=F401 --unsafe-fixes"
95+
}
8796
```
8897

89-
These can be migrated like so:
98+
You can migrate to the new server by using the [`lint.select`](settings.md#select) and
99+
[`configuration`](settings.md#configuration) setting like so:
100+
101+
```json
102+
{
103+
"ruff.lint.select": ["E", "F"],
104+
"ruff.configuration": {
105+
"unsafe-fixes": true,
106+
"lint": {
107+
"unfixable": ["F401"]
108+
}
109+
}
110+
}
111+
```
112+
113+
The following options can be set directly in the editor settings:
114+
115+
- [`lint.select`](settings.md#select)
116+
- [`lint.extendSelect`](settings.md#extendselect)
117+
- [`lint.ignore`](settings.md#ignore)
118+
- [`lint.preview`](settings.md#lint_preview)
119+
120+
The remaining options can be set using the [`configuration`](settings.md#configuration) setting.
121+
122+
### `format.args`
90123

91-
```toml
92-
[language-server.ruff.config]
93-
configuration = "~/.config/custom_ruff_config.toml"
94-
lineLength = 80
124+
If you're also providing formatter flags by using `ruff.format.args` like so:
95125

96-
[language-server.ruff.config.lint]
97-
select = ["E", "F"]
126+
```json
127+
{
128+
"ruff.format.args": "--line-length 80 --config='format.quote-style=double'"
129+
}
98130
```
131+
132+
You can migrate to the new server by using the [`lineLength`](settings.md#linelength) and
133+
[`configuration`](settings.md#configuration) setting like so:
134+
135+
```json
136+
{
137+
"ruff.lineLength": 80,
138+
"ruff.configuration": {
139+
"format": {
140+
"quote-style": "double"
141+
}
142+
}
143+
}
144+
```
145+
146+
The following options can be set directly in the editor settings:
147+
148+
- [`lineLength`](settings.md#linelength)
149+
- [`format.preview`](settings.md#format_preview)
150+
151+
The remaining options can be set using the [`configuration`](settings.md#configuration) setting.
152+
153+
[language server protocol]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
154+
[ruff-lsp]: https://github.com/astral-sh/ruff-lsp
155+
[vs code extension]: https://github.com/astral-sh/ruff-vscode

0 commit comments

Comments
 (0)