vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Change color of methods without reference

Open raulvaldoleiros opened this issue 1 year ago • 2 comments

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.

raulvaldoleiros avatar Jun 21 '24 14:06 raulvaldoleiros

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

rgrunber avatar Jun 24 '24 15:06 rgrunber

Hi @rgrunber,

Thanks for the update. For private methods sonarlint shows a warning message and change the method color to grey. image

For non-private methods the referencesCodeLens shows there isn't references but don't change the method color. image

I will use your suggestion for referenceCodeLens, thanks 👍 IMHO this improvement should be considerer for your future backlog.

raulvaldoleiros avatar Jul 02 '24 08:07 raulvaldoleiros

Agreed. It would be better to have a warning like it does for private methods.

rcsilva83 avatar Jul 03 '25 12:07 rcsilva83

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.

rgrunber avatar Jul 03 '25 12:07 rgrunber