mirror of https://github.com/astral-sh/ruff
docs: revise Ruff setup instructions for Zed editor (#20935)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
76127e5fb5
commit
c6573b16ac
|
|
@ -422,29 +422,12 @@ bundle for TextMate.
|
||||||
|
|
||||||
## Zed
|
## Zed
|
||||||
|
|
||||||
Ruff is available as an extension for the Zed editor. To install it:
|
Ruff support is now built into Zed (no separate extension required).
|
||||||
|
|
||||||
1. Open the command palette with `Cmd+Shift+P`
|
By default, Zed uses Ruff for formatting and linting.
|
||||||
1. Search for "zed: extensions"
|
|
||||||
1. Search for "ruff" in the extensions list and click "Install"
|
|
||||||
|
|
||||||
To configure Zed to use the Ruff language server for Python files, add the following
|
To set up editor-wide Ruff options, provide the [server settings](settings.md)
|
||||||
to your `settings.json` file:
|
under the [`lsp.ruff.initialization_options.settings`](https://zed.dev/docs/configuring-zed#lsp) key of your `settings.json` file:
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"languages": {
|
|
||||||
"Python": {
|
|
||||||
"language_servers": ["ruff"]
|
|
||||||
// Or, if there are other language servers you want to use with Python
|
|
||||||
// "language_servers": ["pyright", "ruff"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To configure the language server, you can provide the [server settings](settings.md)
|
|
||||||
under the [`lsp.ruff.initialization_options.settings`](https://zed.dev/docs/configuring-zed#lsp) key:
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -452,7 +435,7 @@ under the [`lsp.ruff.initialization_options.settings`](https://zed.dev/docs/conf
|
||||||
"ruff": {
|
"ruff": {
|
||||||
"initialization_options": {
|
"initialization_options": {
|
||||||
"settings": {
|
"settings": {
|
||||||
// Ruff server settings goes here
|
// Ruff server settings go here
|
||||||
"lineLength": 80,
|
"lineLength": 80,
|
||||||
"lint": {
|
"lint": {
|
||||||
"extendSelect": ["I"],
|
"extendSelect": ["I"],
|
||||||
|
|
@ -464,22 +447,14 @@ under the [`lsp.ruff.initialization_options.settings`](https://zed.dev/docs/conf
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can configure Ruff to format Python code on-save by registering the Ruff formatter
|
[`format_on_save`](https://zed.dev/docs/configuring-zed#format-on-save) is enabled by default.
|
||||||
and enabling the [`format_on_save`](https://zed.dev/docs/configuring-zed#format-on-save) setting:
|
You can disable it for Python by changing `format_on_save` in your `settings.json` file:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"languages": {
|
"languages": {
|
||||||
"Python": {
|
"Python": {
|
||||||
"language_servers": ["ruff"],
|
"format_on_save": "off"
|
||||||
"format_on_save": "on",
|
|
||||||
"formatter": [
|
|
||||||
{
|
|
||||||
"language_server": {
|
|
||||||
"name": "ruff"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -492,40 +467,12 @@ You can configure Ruff to fix lint violations and/or organize imports on-save by
|
||||||
{
|
{
|
||||||
"languages": {
|
"languages": {
|
||||||
"Python": {
|
"Python": {
|
||||||
"language_servers": ["ruff"],
|
"code_actions_on_format": {
|
||||||
"format_on_save": "on",
|
|
||||||
"formatter": [
|
|
||||||
// Fix all auto-fixable lint violations
|
|
||||||
{ "code_action": "source.fixAll.ruff" },
|
|
||||||
// Organize imports
|
// Organize imports
|
||||||
{ "code_action": "source.organizeImports.ruff" }
|
"source.organizeImports.ruff": true,
|
||||||
]
|
// Fix all auto-fixable lint violations
|
||||||
}
|
"source.fixAll.ruff": true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Taken together, you can configure Ruff to format, fix, and organize imports on-save via the
|
|
||||||
following `settings.json`:
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
|
|
||||||
For this configuration, it is important to use the correct order of the code action and
|
|
||||||
formatter language server settings. The code actions should be defined before the formatter to
|
|
||||||
ensure that the formatter takes care of any remaining style issues after the code actions have
|
|
||||||
been applied.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"languages": {
|
|
||||||
"Python": {
|
|
||||||
"language_servers": ["ruff"],
|
|
||||||
"format_on_save": "on",
|
|
||||||
"formatter": [
|
|
||||||
{ "code_action": "source.fixAll.ruff" },
|
|
||||||
{ "code_action": "source.organizeImports.ruff" },
|
|
||||||
{ "language_server": { "name": "ruff" } }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue