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

ruff server setting enabling code actions on save #11756

Open
DanCardin opened this issue Jun 5, 2024 · 4 comments
Open

ruff server setting enabling code actions on save #11756

DanCardin opened this issue Jun 5, 2024 · 4 comments
Labels
server Related to the LSP server

Comments

@DanCardin
Copy link
Contributor

In the PR for adding the organizeImports code action, i saw a reference to:

  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": "explicit",
      "source.organizeImports": "explicit"
    },
    "editor.defaultFormatter": "charliermarsh.ruff"
  }

which, as far as i can tell, is a VSCode specific thing. Per astral-sh/ruff-lsp#409 or astral-sh/ruff-lsp#335, I'd love for there to be a ruff server-specific setting that optionally enables either/or both of organizeImports or fixAll actions on lsp format.

Personally, I'd likely enable just the organizeImports on save (which i see no reason ever to not run, which is why i'd rather have it automatic than a code action i need to remember to perform), perhaps not fixAll.

@snowsignal snowsignal added the server Related to the LSP server label Jun 5, 2024
@snowsignal
Copy link
Member

snowsignal commented Jun 5, 2024

Thanks for opening this feature request, @DanCardin!

I do think this would a setting worth exploring for editors that don't have a way to run code actions / commands on save.

I'd love for there to be a ruff server-specific setting that optionally enables either/or both of organizeImports or fixAll actions on lsp format.

Just to clarify - are you also proposing that we introduce a separate setting to enable running organizeImports / fixAll when we format?

@DanCardin
Copy link
Contributor Author

Per my parenthesis block in the OP, i'd personally be happy with an organizeImportsOnFormat = true or onFormat = {organizeImports = true}} or whatever server setting (separate from the normal project-specific ruff config).

But with that said, I could imagine (by looking at astral-sh/ruff-lsp#335) that someone might also want to enable fixAll on save too. They're essentially the same feature request. i'm just not personally invested in having both.

@snowsignal
Copy link
Member

Okay, thanks for clarifying 👍

@T-256
Copy link
Contributor

T-256 commented Jun 8, 2024

Another usecase at here is you always trigger format action manually and you didn't set code actions on save. I usually organize imports, format, and fix violations after I complemented the source of target module.
Currently I most use 3 actions each time I finished coding, it'd be nice to have three into one command.

Proposal

ruff server

Editor settings:

{
    "ruff.format.action": {
        "fix": true,
        "isort": true,
        "style": true,
    }
}
  • By default, ONLY style enabled.
  • Format Document will respect these settings, Format Selection ignores these settings.
  • When ruff.organizeImports and/or ruff.fixAll editor settings are disabled, revealment enabled options don't have affect in format actions.
  • Priority on which should be applied first when multi actions enabled: isort > fix > style. We could have separated settings for prioritization, but I think this is good default for now.

ruff cli

The Ruff CLI needs further discussion around new command (e.g. ruff action --fix --isort--no-style).
Also, see this most-wanted feature request: #8232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
Development

No branches or pull requests

3 participants