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 code_actions as formatter type #10121

Merged
merged 3 commits into from
Apr 3, 2024
Merged

Add code_actions as formatter type #10121

merged 3 commits into from
Apr 3, 2024

Conversation

mrnugget
Copy link
Member

@mrnugget mrnugget commented Apr 3, 2024

This fixes #8992 and solves a problem that ESLint/Prettier/... users have been running into:

They want to format only with ESLint, which is not a primary language server (so formatter: language server does not help) and it is not a formatter.

What they want to use is what they get when they have configured something like this:

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

BUT they don't want to run the formatter.

So what this PR does is to add a new formatter type: code_actions.

With that, users can only use code actions to format:

{
  "languages": {
    "JavaScript": {
      "formatter": {
        "code_actions": {
          "source.fixAll.eslint": true
        }
      }
    }
  }
}

This means that when formatting (via editor: format or on-save) only the code actions that are specified are being executed, no formatter.

Release Notes:

  • Added a new formatter/format_on_save option: code_actions. When configured, this uses language server code actions to format a buffer. This can be used if one wants to, for example, format a buffer with ESLint and not run prettier or another formatter afterwards. Example configuration: {"languages": {"JavaScript": {"formatter": {"code_actions": {"source.fixAll.eslint": true}}}}} (#8992).

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 3, 2024
This fixes #8992 and solves a problem that ESLint/Prettier/... users have been
running into:

They want to format _only_ with ESLint, which is *not* a primary language server
(so `formatter: language server` does not help) and it is not a formatter.

What they want to use is what they get when they have configured something like this:

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

BUT they don't want to run the formatter.

So what this PR does is to add a new formatter type: `code_actions`.

With that, users can only use code actions to format:

```json
{
  "languages": {
    "JavaScript": {
      "formatter": {
        "code_actions": {
          "source.fixAll.eslint": true
        }
      }
    }
  }
}
```

This means that when formatting (via `editor: format` or on-save) only the code actions
that are specified are being executed, no formatter.

Co-authored-by: JH Chabran <jh@chabran.fr>
@mrnugget mrnugget force-pushed the code-actions-formatter branch from b04733f to 5afbcc6 Compare April 3, 2024 13:51
mrnugget and others added 2 commits April 3, 2024 16:02
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
@mrnugget mrnugget merged commit eb231d0 into main Apr 3, 2024
9 checks passed
@mrnugget mrnugget deleted the code-actions-formatter branch April 3, 2024 14:16
mrnugget added a commit that referenced this pull request Apr 4, 2024
This documents what was introduced in #10121 and shipped in 0.130.x

Release Notes:

- N/A
@Mau-MD
Copy link

Mau-MD commented Apr 18, 2024

Love this! Tysm

@ramipellumbi
Copy link
Contributor

This is awesome! I have been inching my way towards Zed from VsCode and I think this is what I needed to do my Typescript development on Zed full time (I almost exclusively use it for Python outside of Jupyter notebooks). Keep up the great work :)

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.

Add ability to only run code_actions on format, no formatter
4 participants