neovim+nvim-lspconfig+ruff_lsp+pyright ,ruff_lsp code action not work
hyawara opened this issue · 11 comments
Can you expand on what's not working? I think there are no imports to organize nor any rule which has a fix available. So, both actions should yield no results.
Are you expecting Ruff to add the json
import because F821
is raised? If so, I can explain what's going on here else I'm unable to follow what you're saying.
Yes, I hope so, because when I use vscode or idea, the prompt pops up and I can do that
In other words, I wanted to use its import function or fix function, but it didn't work in neovim
Ruff doesn't provide an autofix for this violation; the prompt you see in VSCode is most likely Pylance so I believe the issue here is with pyright, not Ruff :)
So, ruff_lsp is just a hint, and the actual operation should be handled by pyright
If this is the case, I understand ruff _ lsp wrong and need to query the pyright to deal with it
Not exactly. I think you might be confused here. Let me give a quick explanation about what's going on here:
There are 2 types of code actions you're seeing in Neovim - (1) is to add a noqa
comment to disable the violation on the line where it's being raised, (2) and (3) are source level code actions. These source level code actions are always shown even if they're no-op.
ruff-lsp
is basically the LSP implementation which is to say it kinda is a layer on top of Ruff. Everything you see in your editor is coming from Ruff and can be seen when running the ruff
CLI as well.
Now, you've a violation in your file (F821
) and you want to run the Fix All
code action. This code action applies fixes for all violations which has an auto-fix available. You can find this info here (https://docs.astral.sh/ruff/rules/). If the rule has the 🛠️ emoji, Ruff can fix these issues. The F821
violation doesn't have a fix for it which is why nothing happens when you select the "Fix All" code action.
It's recommended to use other Python language server such as Pyright with ruff-lsp as we don't provide other language features such as auto-completion, goto definition, etc. I hope this helps. Feel free to ask any other questions you might have. I'll close the issue.
@trag1c By prompts I'm assuming you mean the code actions and if so, they're coming from Ruff (prefixed by "Ruff").