microsoft / microsoft/language-server-protocol
Feature Request: A mechanism for marking code as unused, but not actionable
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13k
- Forks
- 1k
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 10
Description
In a language like Python, there are scenarios where you end up with unused variables that are still very much necessary. For example, if you're implementing a method signature, you can end up defining parameters that are unused, but still must be be there in order to preserve the arity of the function. (Furthermore, you often are not even free to rename them to something obviously unused because Python supports invoking functions with named parameters.)
It's nice for IDEs to be able to give a visual indicator that these variables are unused without telling the user that there's something actionable here.
There seems to be disagreement in the ecosystem about if the Language Server Protocol is capable of expressing this. I've read everything I could on this, and my opinion is that it does not.
- Some tools (Pyright, neodim, VS Code, maybe others) treat the pair
(DiagnosticSeverity.Hint, DiagnosticTag.Unnecessary)as "non-actionable unused code". - Other tools (notably Neovim, I haven't checked other popular IDEs) choose to treat all diagnostics (including the
(DiagnosticSeverity.Hint, DiagnosticTag.Unnecessary)pair) as actionable.
One of Neovim's maintainers sought clarity on this in https://github.com/microsoft/language-server-protocol/issues/1696, and the issue was closed with this message:
I will close the issue since I really don't want to enforce UI rendering in the LSP specification.
I totally get that UI rendering is not in scope for the Language Server Protocol. But perhaps the concept of "actionability" is? Is there some way we can clarify or change the Language Server Protocol to support this?
A few proposals, in no particular order:
- Update the docstring on
DiagnosticTag.Unnecessaryto clarify that is it non-actionable.- This would be consistent with what Pyright does: it emits this diagnostic at
(DiagnosticSeverity.Hint, DiagnosticTag.Unnecessary). Relevant code here. - This would be inconsistent with what rust-analyzer does: it emits this diagnostic at
(DiagnosticSeverity.Warning, DiagnosticTag.Unnecessary). Relevant code: here's theDiagnosticTag, the severity ultimately comes fromcargo check, which emits this as a "warning".
- This would be consistent with what Pyright does: it emits this diagnostic at
- Update the docstring on
DiagnosticTag.Unnecessaryto clarify that it is non-actionable withDiagnosticSeverity.Hint, but is actionable at other severities.- This would be consistent with both Pyright and rust-analyzer. I haven't explored other LSP servers, but would be happy to do so if there's interest in moving this forward.
- Add a new
DiagnosticTag.Unused(or perhapsDiagnosticTag.Unreferenced) that is clearly documented as non-actionable.- If we made this change, ideally we'd also clarify that
DiagnosticTag.Unnecessaryis actionable. Or we deprecateDiagnosticTag.Unnecessaryand add an alternative that is clearly documented as actionable. - For the record, I proposed something similar to this in https://github.com/microsoft/language-server-protocol/issues/2025 before I fully understood the issue.
- If we made this change, ideally we'd also clarify that
- Deprecate
DiagnosticTagentirely, instead do this with semantic tokens.- There's some confusion in the ecosystem about if this is actually already the plan. I filed https://github.com/microsoft/language-server-protocol/issues/2024 to seek clarity on this.
Does this feel like something that could be in scope for the Language Server Protocol? If so, I'd be happy to help move this forward.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the DiagnosticTag behavior described in this issue and the linked LSP discussions #1696, #2024, and #2025. Compare the four proposals and determine whether the protocol should clarify existing semantics, add a tag, or use semantic tokens; done means a specific, agreed direction for the LSP specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100