You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I write and develop in Java a lot of code is written and changed, due to nature of development. Someties is happens that some variables or even methods don't get used as initially thought, it would be beneficial if there is a way to provide unused method, field highlight via graying out the field name, or method name respectively.
Extension version: 1.28.1
VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:14:59.643Z)
OS version:
Modes:
public modifier means a 3rd party consumer could actually use your code (eg. you're building a library), so would report false-positive "unused" diagnostics.
It's unlikely such feature will land in vscode-java.
Now if you really really want to get that feature working in vscode-java, I'd suggest you write an extension for vscode-java, that would embed https://marketplace.eclipse.org/content/unnecessary-code-detector, stripped of all its UI dependencies. Then you may be get something working. maybe.
@fbricon the feature of showing unused public methods in greyed out font is extremely useful in IntelliJ to spot dead code. It doesn't need to be treated as a problem or trigger a warning, but it's a nice hint that code might have been left behind. I hope this feature could be implemented in VSCode as well, I'm missing it a lot when coding in VSCode.
Activity
fbricon commentedon Mar 13, 2024
This is what you get today:
mamilic commentedon Mar 13, 2024
Do apologies, didn't know that it works in some cases and in some it doesn't. It is not working in follwoing cases
Would it be possivle for example in case of Constants class, as it does have any references to be grayed out?

fbricon commentedon Mar 13, 2024
publicmodifier means a 3rd party consumer could actually use your code (eg. you're building a library), so would report false-positive "unused" diagnostics.mamilic commentedon Mar 13, 2024
Thank you for explanation. Just curious, what would be your approach finding and removing unused public methods, fields, enums from code?
fbricon commentedon Mar 13, 2024
You can try using Intellij, but that feature seems pretty controversial, so much so that people tend to disable it.
It's unlikely such feature will land in vscode-java.
Now if you really really want to get that feature working in vscode-java, I'd suggest you write an extension for vscode-java, that would embed https://marketplace.eclipse.org/content/unnecessary-code-detector, stripped of all its UI dependencies. Then you may be get something working. maybe.
mamilic commentedon Mar 14, 2024
Thnank you for suggestions.
bigunyak commentedon Mar 22, 2026
@fbricon the feature of showing unused public methods in greyed out font is extremely useful in IntelliJ to spot dead code. It doesn't need to be treated as a problem or trigger a warning, but it's a nice hint that code might have been left behind. I hope this feature could be implemented in VSCode as well, I'm missing it a lot when coding in VSCode.