-
Notifications
You must be signed in to change notification settings - Fork 46
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
How to use ruff-lsp along with pyright in Neovim #384
Comments
Hey, thanks for using Ruff!
Well, I just figured out how to disable diagnostics in Pyright, thanks! You can put the following in your config which disables linting, import sorting and type checking from Pyright and thus only provides completions, goto(s), etc. pyright = {
settings = {
pyright = {
disableOrganizeImports = true, -- Using Ruff
},
python = {
analysis = {
ignore = { '*' }, -- Using Ruff
typeCheckingMode = 'off', -- Using mypy
},
},
},
} I'll document this in the README. |
Thanks a lot @dhruvmanila. It works! |
## Summary Update Neovim documentation with the following changes: - Fix the code to disable hover capability. Earlier, it would disable for _every_ language server while we only want to disable it for `ruff-lsp`. - Add an example to disable diagnostics and import sorting from Pyright. fixes: #384
@dhruvmanila Thank you!!!! Related to: neovim/nvim-lspconfig#726 |
For me it seems that
also disables pyright's typing, how would one let ruff manage linting etc but let pyright provide typing errors ? |
Hi, as mentioned above by @StitiFatah is it possible to preserve pyright's typing? |
Unfortunately, I don't think it's possible to just enable type checking for Pyright and disable other diagnostics. One would need to manually go through the list of diagnostics supported by Pyright (https://github.com/microsoft/pyright/blob/main/docs/configuration.md#type-check-diagnostics-settings) and disable the ones which overlaps with Ruff's rules. |
After using mypy for a bit instead of pyright I feel that mypy misses a lot of things pyright doesn't. I've thus removed mypy, removed that : analysis = {
-- Ignore all files for analysis to exclusively use Ruff for linting
ignore = { "*" },
}, and also added this (which i found here) to my lspconfig configuration
And it sseems to do the trick. It fixes duplicates like We'll see if it removes enough duplicates. |
Thanks for the suggestion! |
My lspconfig actually includes:
How could I include this change? |
Well it seems that there are still duplicates, from my current understanding the settings above only remove what they call "hints" microsoft/pyright#3929 (reply in thread) Errors like those for undefined variables are still emitted by both Pyright and Ruff. (as pointed out by a message above which seems to have been deleted) Those pyright errors are documented here but I couldn't figure out where to place them in my So for now I'm settling with disabling those duplicates from the Ruff side. For undefined variables for example one would do : ruff_lsp={
init_options = {
settings = {
args = {
"--ignore=F821",
},
},
},
} It'd be helpful if we could document duplicates somewhere since pyright + ruff seems like a popular combo. Edit : btw the snippet from my previous message can be abbreviated as this in a cleaner way : capabilities = {
textDocument = {
publishDiagnostics = {
tagSupport = {
valueSet = { 2 },
},
},
},
}, |
@steakhutzeee |
I'm using this configuration basically https://github.com/ChristianChiarulli/nvim/blob/master/lua/user/lspconfig.lua As you can see the capabilities are already defined there. And he configured the servers in a separate dir https://github.com/ChristianChiarulli/nvim/tree/master/lua/user/lspsettings So you think there is a way to add the settings in the lsp config or in a dedicated file separately? I'm going to try but have no idea if it's a problem to set capabilites in different locations. EDIT: Ok so i left the lspconfig as is and edited pyright and ruff_lsp configs separately in their files. Looks it works but not sure if something is wrong with the capabilities set both in lspconfig and (maybe overwritten?) in the pyright config. |
I cant guarantee it but my guess is that it'd overwrite the main Or you could let them in this file, and do like he did with the lua lsp with a |
you can do this to use pyright with ruff_lsp and ignore pyright's diagnostics to avoid duplicates (but you have to disable them one by one) while still keeping pyright's type checking: settings = {
pyright = {
disableOrganizeImports = true,
disableTaggedHints = true,
},
python = {
analysis = {
diagnosticSeverityOverrides = {
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#type-check-diagnostics-settings
reportUndefinedVariable = "none",
},
},
},
},
|
Ruff-LSP handles most of the things. I want to use
pyright
only for things whichruff-lsp
doesn't do. I am unable to disablepyright
for things whichruff-lsp
already does.The
README
and documentation mentions about usingruff-lsp
with anotherlsp
:How do we disable
pyright
for linting and formatting?I read through all existing issues but couldn't find a complete configuration of using
pyright
along withruff
.I am using this configuration, but it does linting using both
pyright
andruff
.Please share your config if anyone has been able to use
pyright
along withruff-lsp
without the overlaps.The text was updated successfully, but these errors were encountered: