Skip to content
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

Unreferenced/Unused Method, Field highlight #3532

Closed
mamilic opened this issue Mar 13, 2024 · 6 comments
Closed

Unreferenced/Unused Method, Field highlight #3532

mamilic opened this issue Mar 13, 2024 · 6 comments

Comments

@mamilic
Copy link

mamilic commented Mar 13, 2024

Type: Feature Request

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:

@fbricon
Copy link
Collaborator

fbricon commented Mar 13, 2024

This is what you get today:

Screenshot 2024-03-13 at 16 05 03

@mamilic
Copy link
Author

mamilic commented 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

  • With Enums
  • With public static final fields and public final field
  • With public class methods

Would it be possivle for example in case of Constants class, as it does have any references to be grayed out?
image

@fbricon
Copy link
Collaborator

fbricon commented Mar 13, 2024

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.

@mamilic
Copy link
Author

mamilic commented 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
Copy link
Collaborator

fbricon commented 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
Copy link
Author

mamilic commented Mar 14, 2024

Thnank you for suggestions.

@mamilic mamilic closed this as completed Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants