-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Pyright configuration for disabling hint diagnostics #726
Comments
You can pass any settings to pyright that you would with any other client, just override the If you want to disable showing hints (generally), you'll need to override the diagnostic handler in neovim to pass a severity limit for virtual text. If you want to only disable one type of hint, I guess you could write a filtering function to filter out diagnostics of the type you are seeing (both of which, are not implemented/associated with nvim-lspconfig, which only handles starting your language server and passing initialization options). |
@horta Did you ever find out a way to do this? I am so close to giving up on the LSP-ecosystem in neovim because it keeps telling me im using |
In that example why would you not make it a static method? Something like https://stackoverflow.com/questions/1697501/staticmethod-with-property. The diagnostic is correct, self is unused. FWIW you can pass an arbitrary filter on diagnostics by overriding the diagnostic handlers if it really bothers you. |
@mjlbach out of curiosity, how would one go about doing that? I didn't know we could filter diagnostics like that :o |
You have access to the diagnostic list in on_publish_diagnostics, see here for an example of how it's sorted (you could apply a filter as well) https://github.com/neovim/neovim/blob/d2be261e8d1bcf165346255ae701564a5f62bf7d/runtime/lua/vim/lsp/diagnostic.lua#L1008-L1013 You'd want to make a custom version of that function, and then override the handler to call that. https://github.com/neovim/neovim/blob/d2be261e8d1bcf165346255ae701564a5f62bf7d/runtime/lua/vim/lsp/diagnostic.lua#L967-L983 |
Anyways, this isn't neovim's fault, pyright may or may not have some configuration option you can pass to it, we literally just pipe the diagnostics directly from pyright. |
@imsofi update pyright to the latest version. This behaviour has been fixed for a while now. |
Here's the related (closed) issue for more information: microsoft/pylance-release#194 |
I don't remember but
might do the trick... |
For anyone coming back to this, I am using the following based on @mjlbach's suggestions: function filter(arr, func)
-- Filter in place
-- https://stackoverflow.com/questions/49709998/how-to-filter-a-lua-array-inplace
local new_index = 1
local size_orig = #arr
for old_index, v in ipairs(arr) do
if func(v, old_index) then
arr[new_index] = v
new_index = new_index + 1
end
end
for i = new_index, size_orig do arr[i] = nil end
end
function filter_diagnostics(diagnostic)
-- Only filter out Pyright stuff for now
if diagnostic.source ~= "Pyright" then
return true
end
-- Allow kwargs to be unused, sometimes you want many functions to take the
-- same arguments but you don't use all the arguments in all the functions,
-- so kwargs is used to suck up all the extras
if diagnostic.message == '"kwargs" is not accessed' then
return false
end
-- Allow variables starting with an underscore
if string.match(diagnostic.message, '"_.+" is not accessed') then
return false
end
return true
end
function custom_on_publish_diagnostics(a, params, client_id, c, config)
filter(params.diagnostics, filter_diagnostics)
vim.lsp.diagnostic.on_publish_diagnostics(a, params, client_id, c, config)
end
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
custom_on_publish_diagnostics, {}) |
There is a much easier way to disable these hints. Pyright sends these hints to neovim because neovim is specifically asking for them (and probably shouldn't be -- see this discussion and this comment).
For reference, here are the tags. |
@Swoogan I prefer my method. It's more customizable. I can choose exactly what diagnostics I want to ignore. For example, |
@MarcelRobitaille It certainly is more customizable. In my case I wanted all hints to be removed because I have them coming from other tools and was getting duplicate diagnostics. I wonder though, could it be implemented in the client's handler instead of globally? Then you wouldn't need to check the source. For example:
|
@Swoogan I will try that, thanks! |
@Swoogan yes, that is possible. |
For anyone that is using LunarVim or
That said, I believe this is a bug since it is stated very clear here that Clients are allowed to render diagnostics with this tag faded out when the tag is 1. |
These largely duplicate messages from Ruff. neovim/nvim-lspconfig#726 (comment)
those using lazyvim can add the following to a file in .config/nvim/lua/plugins as mentioned here
|
According to: microsoft/pyright#982 (comment)
AFAIK, there is not way to currently disable it using nvim-lspconfig:
Here is the diagnostic I would like to suppress:
The text was updated successfully, but these errors were encountered: