Skip to content

Commit

Permalink
Add setup docs for Zed
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 25, 2024
1 parent f0fc6a9 commit 4a125b0
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions docs/editors/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,124 @@ Alternatively, it can be used via the [Apheleia](https://github.com/radian-softw

Ruff is also available via the [`textmate2-ruff-linter`](https://github.com/vigo/textmate2-ruff-linter)
bundle for TextMate.

## Zed

Ruff is available as an extension for the Zed editor. To install it:

1. Open the command palette with `Cmd+Shift+P`
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 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
{
"lsp": {
"ruff": {
"initialization_options": {
"settings": {
// Ruff server settings goes here
"lineLength": 80,
"lint": {
"extendSelect": ["I"],
}
}
}
}
}
}
```

!!! note
Configuring multiple formatters for a given language requires the [preview
version](https://zed.dev/releases/preview) of Zed.

You can configure Ruff to format Python code on-save by registering the Ruff formatter
and enabling the [`format_on_save`](https://zed.dev/docs/configuring-zed#format-on-save) setting:

```json
{
"languages": {
"Python": {
"format_on_save": "on",
"formatter": [
{
"language_server": {
"name": "ruff"
}
}
]
}
}
}
```

You can configure Ruff to fix lint violations and/or organize imports on-save by enabling the
`source.fixAll.ruff` and `source.organizeImports.ruff` code actions respectively:

```json
{
"languages": {
"Python": {
"format_on_save": "on",
"formatter": [
{
"code_actions": {
// Fix all auto-fixable lint violations
"source.fixAll.ruff": true,
// Organize imports
"source.organizeImports.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
[`code_actions_on_format`](https://zed.dev/docs/configuring-zed#code-actions-on-format) setting
instead of the [`code_actions`](https://zed.dev/docs/configuring-zed#code-actions) setting to
ensure that Ruff runs the code actions after formatting the code.

```json
{
"languages": {
"Python": {
"format_on_save": "on",
"formatter": [
{
"language_server": {
"name": "ruff"
}
}
],
"code_actions_on_format": {
"source.organizeImports.ruff": true,
"source.fixAll.ruff": true
}
}
}
}
```

0 comments on commit 4a125b0

Please sign in to comment.