Change color of methods without reference
It would be great if vscode java changed the color method, maybe to grey, on methods without any reference to it.
Similar to what intellij have.
There's a few workarounds / other ways to achieve something similar, though I guess this is definitely something that could be done, given that we have the data from reference code lens (ie. 0 references), and could just use the semantic highlighting on the language server side to correctly set the highlighting.
Using java.referencesCodeLens.enabled: true (assuming editor.codeLens: true is also set), you would see 0 references over any method declaration that is not referenced anywhere.
For private methods only (a little simpler because they need not be searched throughout the entire project), there's :
.vscode/settings.json
{
"java.settings.url": ".vscode/settings.prefs",
}
settings.prefs
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
Hi @rgrunber,
Thanks for the update.
For private methods sonarlint shows a warning message and change the method color to grey.
For non-private methods the referencesCodeLens shows there isn't references but don't change the method color.
I will use your suggestion for referenceCodeLens, thanks 👍 IMHO this improvement should be considerer for your future backlog.
Agreed. It would be better to have a warning like it does for private methods.
I never really mentioned it in my original comments (just the workarounds), but the main problem is performance. For a given public method declaration, it can take a while (for large projects) to compute all the references. Maybe it would go a bit faster since we can terminate a search the moment we find a reference. However we would effectively be enabling java.referencesCodeLens.enabled-like computations, but the reason we have that setting is to give users the option to improve performance.
This is definitely possible though.