Skip to content

Commit 6263923

Browse files
authoredMay 22, 2024··
Update documentation for ruff server with new migration guide (#11499)
## Summary Introduces a migration guide from `ruff-lsp` to `ruff server` and makes small updates to the `README.md`.
1 parent 94abea4 commit 6263923

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-3
lines changed
 

‎crates/ruff_server/README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,33 @@ files in your editor's workspace, and will refresh its in-memory configuration w
99

1010
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.
1111

12-
- Visual Studio Code: Install the [Ruff extension from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff). 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.
13-
- Neovim: See the [Neovim setup guide](docs/setup/NEOVIM.md).
12+
#### Visual Studio Code
13+
14+
Install the [Ruff extension from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff).
15+
16+
As this server is still in beta, you will need to enable the `Native Server` extension setting:
17+
18+
![A screenshot showing an enabled "Native Server" extension setting in the VS Code settings view](assets/nativeServer.png)
19+
20+
You can also set it in your user / workspace JSON settings as follows:
21+
22+
```json
23+
{
24+
"ruff.nativeServer": true
25+
}
26+
```
27+
28+
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.
29+
30+
#### Neovim
31+
32+
See the [Neovim setup guide](docs/setup/NEOVIM.md).
33+
34+
#### Helix
35+
36+
See the [Helix setup guide](docs/setup//HELIX.md).
37+
38+
If you are transferring your configuration from `ruff-lsp`, regardless of editor, there are several settings which have changed or are no longer available which you should be aware of. See the [migration guide](docs/MIGRATION.md) for more details.
1439

1540
### Contributing
1641

22.9 KB
Loading

‎crates/ruff_server/docs/MIGRATION.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
## Migrating From `ruff-lsp`
2+
3+
`ruff server`'s configuration is significantly different from `ruff-lsp`, and as such you may need to update your existing configuration.
4+
5+
> \[!NOTE\]
6+
>
7+
> The VS Code extension settings have documentation that will tell you whether `ruff server` supports a given setting.
8+
> This migration guide may be more useful for the editors that do not have explicitly documented settings for the language server,
9+
> such as Helix or Neovim.
10+
11+
### Unsupported Settings
12+
13+
Several `ruff-lsp` settings are not supported by `ruff server`. These are, as follows:
14+
15+
- `format.args`
16+
- `ignoreStandardLibrary`
17+
- `interpreter`
18+
- `lint.args`
19+
- `lint.run`
20+
- `logLevel`
21+
- `path`
22+
23+
Note that some of these settings, like `interpreter` and `path`, are still accepted by the VS Code extension. `path`, in particular, can be used to set the ruff binary
24+
used to run `ruff server`. But the server itself will no longer accept these as settings.
25+
26+
### New Settings
27+
28+
`ruff server` introduces several new settings that `ruff-lsp` does not have. These are, as follows:
29+
30+
- `configuration`: This is a path to a `ruff.toml` or `pyproject.toml` file to use for configuration. By default, Ruff will discover configuration for each project from the filesystem, mirroring the behavior of the Ruff CLI.
31+
- `configurationPreference`: Used to specify how you want to resolve server settings with local file configuration. The following values are available:
32+
- `"editorFirst"`: The default strategy - configuration set in the server settings takes priority over configuration set in `.toml` files.
33+
- `"filesystemFirst"`: An alternative strategy - configuration set in `.toml` files takes priority over configuration set in the server settings.
34+
- `"editorOnly"`: An alternative strategy - configuration set in `.toml` files is ignored entirely.
35+
- `exclude`: Paths for the linter and formatter to ignore. See [the documentation](https://docs.astral.sh/ruff/settings/#exclude) for more details.
36+
- `format.preview`: Enables [preview mode](https://docs.astral.sh/ruff/settings/#format_preview) for the formatter; enables unstable formatting.
37+
- `lineLength`: The [line length](https://docs.astral.sh/ruff/settings/#line-length) used by the formatter and linter.
38+
- `lint.select`: The rule codes to enable. Use `ALL` to enable all rules. See [the documentation](https://docs.astral.sh/ruff/settings/#lint_select) for more details.
39+
- `lint.extendSelect`: Enables additional rule codes on top of existing configuration, instead of overriding it. Use `ALL` to enable all rules.
40+
- `lint.ignore`: Sets rule codes to disable. See [the documentation](https://docs.astral.sh/ruff/settings/#lint_ignore) for more details.
41+
- `lint.preview`: Enables [preview mode](https://docs.astral.sh/ruff/settings/#lint_preview) for the linter; enables unstable rules and fixes.
42+
43+
Several of these new settings are replacements for the now-unsupported `format.args` and `lint.args`. For example, if you have been passing in `--select=<RULES>`
44+
to `lint.args`, you can migrate to the new server by using `lint.select` with a value of `["<RULES>"]`.
45+
46+
### Examples
47+
48+
Let's say you have these settings in VS Code:
49+
50+
```json
51+
{
52+
"ruff.lint.args": "--select=E,F --line-length 80 --config ~/.config/custom_ruff_config.toml"
53+
}
54+
```
55+
56+
These can be migrated to the new language server like so:
57+
58+
```json
59+
{
60+
"ruff.configuration": "~/.config/custom_ruff_config.toml",
61+
"ruff.lineLength": 80,
62+
"ruff.lint.select": ["E", "F"]
63+
}
64+
```
65+
66+
Similarly, let's say you have these settings in Helix:
67+
68+
```toml
69+
[language-server.ruff.config.lint]
70+
args = "--select=E,F --line-length 80 --config ~/.config/custom_ruff_config.toml"
71+
```
72+
73+
These can be migrated like so:
74+
75+
```toml
76+
[language-server.ruff.config]
77+
configuration = "~/.config/custom_ruff_config.toml"
78+
lineLength = 80
79+
80+
[language-server.ruff.config.lint]
81+
select = ["E", "F"]
82+
```

‎crates/ruff_server/docs/setup/HELIX.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ language-servers = ["ruff", "pylsp"]
3434
3535
Once you've set up the server, you should see diagnostics in your Python files. Code actions and other LSP features should also be available.
3636

37-
![image](assets/SuccessfulHelixSetup.png "A screenshot showing an open Python file in Helix with highlighted diagnostics and a code action dropdown menu open")
37+
![A screenshot showing an open Python file in Helix with highlighted diagnostics and a code action dropdown menu open](assets/SuccessfulHelixSetup.png)
3838
*This screenshot is using `select=["ALL]"` for demonstration purposes.*
3939

4040
If you want to, as an example, turn on auto-formatting, add `auto-format = true`:

0 commit comments

Comments
 (0)
Please sign in to comment.