|
| 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 | +``` |
0 commit comments