Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run ESLint (and other non-primary language server) code actions on format #8496

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

mrnugget
Copy link
Member

@mrnugget mrnugget commented Feb 27, 2024

This PR does two things to fix #4325:

  1. It changes the way code_actions_on_format works to send the possibly configured code actions to all (and not just the primary) languages servers. That means configured code actions can now be sent to ESLint, tailwind, ... and other language servers.
  2. It enables codeActionsOnSave by default for ESLint. That does not mean that by default we will run something on save, but only that we enable it for ESLint.

Users can then configure their Zed to run the eslint code action on format. Example, for JavaScript:

    {
      "languages": {
        "JavaScript": {
          "code_actions_on_format": {
            "source.fixAll.eslint": true
          }
        },
      }
    }

Release Notes:

  • Added ability to run ESLint fixes when formatting a buffer. Code actions configured in code_actions_on_format are now being sent to all language servers connected to a buffer, not just the primary one. So if a user now sets "code_actions_on_format": { "source.fixAll.eslint": true } in their Zed settings, the source.fixAll.eslint code action will be sent to ESLint, which is not a primary language server. Since the formatter (prettier, or external commands, or another language server, ...) still runs, it's important that these code actions and the formatter don't clash. (#4325).

Demo:

screenshot-2024-02-28-13.31.27.mp4

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 27, 2024
Previously we only send these code actions to the primary language
server, but with this change we now send to them all language servers.

That's use when we then want to run code actions with eslint or other
secondary language servers.
This setting alone doesn't do anything, but in combination with
0afc524 it allows users to configure their Zed to fix on save:

    {
      "languages": {
        "JavaScript": {
          "code_actions_on_format": {
            "source.fixAll.eslint": true
          }
        },
      }
    }
@mrnugget mrnugget changed the title Eslint codeactions on format Add ability to run ESLint (and other non-primary language server) code actions on format Feb 28, 2024
@mrnugget mrnugget marked this pull request as ready for review February 28, 2024 12:48
@mrnugget mrnugget merged commit f895983 into main Feb 28, 2024
10 checks passed
@mrnugget mrnugget deleted the eslint-codeactions-on-format branch February 28, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native support eslint fix on save
1 participant