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

Organize Imports and Fix All do nothing in helix #249

Closed
bluthej opened this issue Sep 20, 2023 · 6 comments · Fixed by helix-editor/helix#8421
Closed

Organize Imports and Fix All do nothing in helix #249

bluthej opened this issue Sep 20, 2023 · 6 comments · Fixed by helix-editor/helix#8421

Comments

@bluthej
Copy link

bluthej commented Sep 20, 2023

Hey there, I've been using helix for a few weeks now and I'm using ruff-lsp alongside pylsp to hack on some Python code :)
Thanks so much to the maintainers!

I do like to keep my imports tidy, but for some reason it seems like the Organize Imports code action does nothing in helix, and Fix All as well. Removing unused imports works just fine of the other hand. I know it sounds like #28 but since it is closed I'm thinking whatever wasn't right at the time got fixed.

I was wondering if that is a helix issue? I went over to the helix repo but I couldn't find any mention of such a limitation.

Here is some additional info:

  • ruff-lsp version: 0.0.39
  • helix version: built from the master branch on the 20th of September
helix lsp config for Python

[language-server.ruff-lsp]
command = "ruff-lsp"
args = []

[[language]]
name = "python"
formatter = { command = "black", args = ["--quiet", "-"] }
auto-format = true
language-servers = ["ruff-lsp", "pylsp"]

helix log

2023-09-20T22:31:11.028 helix_term::commands::lsp [DEBUG] code action: CodeAction { title: "Ruff: Organize Imports", kind: Some(CodeActionKind("source.organizeImports")), diagnostics: Some([]), edit: None, command: None, is_preferred: None, disabled: None, data: Some(String("file:///home/joffrey/test.py")) }

@bluthej
Copy link
Author

bluthej commented Sep 26, 2023

Ok so after playing around a bit more I found out that if I select the I001 rule in my ruff settings then I have a separate Ruff (I001): Organize imports code action that does sort my imports, in addition to the Ruff: Organize Imports code action that's always there and which does nothing.

I know this sounds a bit like #91, but my point here is that I find it odd that the always-present Ruff: Organize Imports code action does nothing, even though the rule is selected. Also, the Ruff: Fix All code action does nothing, even though there are things to fix. Could that be an issue on the helix side or is everything acting properly and I just have misplaced expectations?

As a user I just find it a bit confusing, and if I can, I would like to spare future users some frustration 😄
So if there is anything I can do to help out I'd be happy to 😃

@charliermarsh
Copy link
Member

Sorry for not getting back to you earlier, and thanks for the kind words.

There are probably two things happening here:

  1. We always show the Ruff: Organize Imports and Ruff: Fix All actions, even if there's nothing to organize or nothing to fix. This can lead to a confusing experience. It makes sense for VS Code, but perhaps not for other LSPs, and we may want to filter them out contextually.
  2. Separately, though, it sounds like those actions aren't doing what you'd expect in Helix, which I need to test.

@charliermarsh
Copy link
Member

Hmm, so after testing, things are actually working correctly for me -- the code actions have the expected effect. And surprisingly, we're only showing Ruff: Organize Imports if there are imports to fix (same for Ruff: Fix All) -- I'd forgotten that we did make it contextual for editors that don't support deferred resolution of actions, so I think (1) shouldn't apply to Helix at least.

Screen Shot 2023-09-26 at 7 34 43 PM Screen Shot 2023-09-26 at 7 34 47 PM Screen Shot 2023-09-26 at 7 34 50 PM Screen Shot 2023-09-26 at 7 35 01 PM

@charliermarsh
Copy link
Member

I don't know that it will resolve it, but you could try using a single language server?

[[language]]
name = "python"
scope = "source.python"
language-server = { command = "ruff-lsp" }
config = { settings = { args = [] } }

@bluthej
Copy link
Author

bluthej commented Sep 27, 2023

Sorry for not getting back to you earlier

No worries 😄

Hmm, so after testing, things are actually working correctly for me

Thx for taking the time to try it out for yourself!

I don't know that it will resolve it, but you could try using a single language server?

So I can confirm that with the latest stable release of helix (23.05) it all works with the config that you provided.

In the current master branch on the other hand the lsp config has changed to allow for multiple language servers on the same buffer, so I cannot test this exact config. I did try an equivalent config, with just ruff-lsp in the language-servers field, but I still get the same behavior I described in the issue.

I guess it's a bug in the master branch so I will open an issue on the helix repo!

I should have thought of testing the latest helix stable release before opening this issue, sorry about that 😅

@bluthej
Copy link
Author

bluthej commented Oct 2, 2023

Fixed by helix-editor/helix#8421.

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

Successfully merging a pull request may close this issue.

2 participants