-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Handling 'unused parameter' hints #107
Comments
Fixed in neoclide/coc.nvim#2538, upgrade to latest coc.nvim and set |
Is there any way to special-case this to only show the parameter grayed out without showing any error information? It seems like a good idea to have a visual hint that a variable is unused but having an error produces a lot of noise. This is what Visual Code seems to do according to this pyright issue where this problem was brought up by several people: microsoft/pyright#1118 |
Also, this new |
@lucatpa Upgrade your coc.nvim, the latest coc can gray out the unused var without an error/warning. |
Thanks @fannheyward! I just upgraded (using the Is this available only on |
@lucatpa the unused var will be grayed out, but if you put your cursor on it, the hint message will still showing. It's the expected behavior. |
I'm caught in the middle of different opinions here, because pyright developers say this should only be a syntax highlight hint and no other visual indication should be shown. For parameters of functions that are fulfilling some API this leaves users in a bad position where they have to chose to have visual noise for irrelevant (and unavoidable) noise (having a popup and a mark in the line) or completely disabling all unused variables hinting. So is there no way to reconcile both projects views on this one? Should I just give up? And I'm not being cynical here, I'm truly hugely thankful to both projects because they make my life so much easier, this is only a tiny nuance. I just want to avoid wasting your and my time if there will be no agreement between both projects. |
For example: #!/usr/bin/env python3
def foo(name):
"""docstring for foo"""
pass The {
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 12
}
},
"message": "\"name\" is not accessed",
"severity": 4,
"source": "Pyright",
"tags": [
1
]
} The diagnostic level is Hint. coc will sign it as In VSCode, I've know your problem, IMO the 'unused parameter' hint is a diagnostic, both coc/VSCode will gray out it, but in coc you will still get the sign noise. You can set
It's OK here. |
OK, I see. Thanks for getting getting involved in the pyright issues. I think the real solution would be to provide a way to ignore unused parameters for certain functions, as stated in pyright issues, because the problem here (or to me) is getting the editor even notifying me, in any way, noisy or not, about something that is expected and I can't possibly fix. Even a gray-out would still be noise, more manageable but noise. I will try the |
Personally, I also had trouble with virtual text. So my solution was this: {"diagnostic.virtualTextLevel": "information"} However I'm unsure what other consequences there are for this. I might be missing something useful. |
This may be a non-solution to others, but personally I "fixed" this by disabling the reporting of unused var from Pyright and use Ruff instead as Ruff can be configured to only report unused vars not starting with |
Note that you also need |
Pyright flags unused function parameters with a hint.
That is often helpful, but when you're trying to satisfy some library's API, you may want to include placeholders for parameters even if a function or method doesn't actually use them. An unused argument warning can be silenced by naming a parameter
_
, but that only works for one parameter. Names can be dundered (like__name__
), but that feels like a hack, and doesn't work for keyword parameters. You could also use*arg
and**kwargs
, but is a bit less clear that having placeholders.According to this, the Pyright language server tags unused parameter hints in some way, and the LSP client can tell Pyright that it doesn't support this tag to prevent Pyright from sending these hints. Possibly coc-pyright could provide an option to disable unused argument hints.
The text was updated successfully, but these errors were encountered: