Add setup docs for Zed editor (#12501) · astral-sh/ruff@6bbb4a2 (original) (raw)

`@@ -372,3 +372,129 @@ Alternatively, it can be used via the [Apheleia](https://github.com/radian-softw

`

372

372

``

373

373

`` Ruff is also available via the textmate2-ruff-linter

``

374

374

`bundle for TextMate.

`

``

375

+

``

376

`+

Zed

`

``

377

+

``

378

`+

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

`

``

379

+

``

380

`` +

  1. Open the command palette with Cmd+Shift+P

``

``

381

`+

  1. Search for "zed: extensions"

`

``

382

`+

  1. Search for "ruff" in the extensions list and click "Install"

`

``

383

+

``

384

`+

To configure Zed to use the Ruff language server for Python files, add the following

`

``

385

`` +

to your settings.json file:

``

``

386

+

``

387


```json

``

388

`+

{

`

``

389

`+

"languages": {

`

``

390

`+

"Python": {

`

``

391

`+

"language_servers": ["ruff"]

`

``

392

`+

// Or, if there are other language servers you want to use with Python

`

``

393

`+

// "language_servers": ["pyright", "ruff"]

`

``

394

`+

}

`

``

395

`+

}

`

``

396

`+

}

`

``

397


```

``

398

+

``

399

`+

To configure the language server, you can provide the server settings

`

``

400

`` +

under the lsp.ruff.initialization_options.settings key:

``

``

401

+

``

402


```json

``

403

`+

{

`

``

404

`+

"lsp": {

`

``

405

`+

"ruff": {

`

``

406

`+

"initialization_options": {

`

``

407

`+

"settings": {

`

``

408

`+

// Ruff server settings goes here

`

``

409

`+

"lineLength": 80,

`

``

410

`+

"lint": {

`

``

411

`+

"extendSelect": ["I"],

`

``

412

`+

}

`

``

413

`+

}

`

``

414

`+

}

`

``

415

`+

}

`

``

416

`+

}

`

``

417

`+

}

`

``

418


```

``

419

+

``

420

`+

!!! note

`

``

421

`+

Support for multiple formatters for a given language is only available in Zed version

`

``

422

`` +

0.146.0 and later.

``

``

423

+

``

424

`+

You can configure Ruff to format Python code on-save by registering the Ruff formatter

`

``

425

`` +

and enabling the format_on_save setting:

``

``

426

+

``

427

`+

=== "Zed 0.146.0+"

`

``

428


 ```json

``

429

`+

{

`

``

430

`+

"languages": {

`

``

431

`+

"Python": {

`

``

432

`+

"format_on_save": "on",

`

``

433

`+

"formatter": [

`

``

434

`+

{

`

``

435

`+

"language_server": {

`

``

436

`+

"name": "ruff"

`

``

437

`+

}

`

``

438

`+

}

`

``

439

`+

]

`

``

440

`+

}

`

``

441

`+

}

`

``

442

`+

}

`

``

443


 ```

``

444

+

``

445

`+

You can configure Ruff to fix lint violations and/or organize imports on-save by enabling the

`

``

446

`` +

source.fixAll.ruff and source.organizeImports.ruff code actions respectively:

``

``

447

+

``

448

`+

=== "Zed 0.146.0+"

`

``

449


 ```json

``

450

`+

{

`

``

451

`+

"languages": {

`

``

452

`+

"Python": {

`

``

453

`+

"format_on_save": "on",

`

``

454

`+

"formatter": [

`

``

455

`+

{

`

``

456

`+

"code_actions": {

`

``

457

`+

// Fix all auto-fixable lint violations

`

``

458

`+

"source.fixAll.ruff": true,

`

``

459

`+

// Organize imports

`

``

460

`+

"source.organizeImports.ruff": true

`

``

461

`+

}

`

``

462

`+

}

`

``

463

`+

]

`

``

464

`+

}

`

``

465

`+

}

`

``

466

`+

}

`

``

467


 ```

``

468

+

``

469

`+

Taken together, you can configure Ruff to format, fix, and organize imports on-save via the

`

``

470

`` +

following settings.json:

``

``

471

+

``

472

`+

!!! note

`

``

473

`+

For this configuration, it is important to use the correct order of the code action and

`

``

474

`+

formatter language server settings. The code actions should be defined before the formatter to

`

``

475

`+

ensure that the formatter takes care of any remaining style issues after the code actions have

`

``

476

`+

been applied.

`

``

477

+

``

478

`+

=== "Zed 0.146.0+"

`

``

479


 ```json

``

480

`+

{

`

``

481

`+

"languages": {

`

``

482

`+

"Python": {

`

``

483

`+

"format_on_save": "on",

`

``

484

`+

"formatter": [

`

``

485

`+

{

`

``

486

`+

"code_actions": {

`

``

487

`+

"source.organizeImports.ruff": true,

`

``

488

`+

"source.fixAll.ruff": true

`

``

489

`+

}

`

``

490

`+

},

`

``

491

`+

{

`

``

492

`+

"language_server": {

`

``

493

`+

"name": "ruff"

`

``

494

`+

}

`

``

495

`+

}

`

``

496

`+

]

`

``

497

`+

}

`

``

498

`+

}

`

``

499

`+

}

`

``

500


 ```