Skip to content

Unreferenced/Unused Method, Field highlight #3532

Closed

Description

@mamilic

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:

Activity

  1. fbricon commented on Mar 13, 2024

    @fbricon
    Collaborator

    This is what you get today:

    Screenshot 2024-03-13 at 16 05 03
  2. mamilic commented on Mar 13, 2024

    @mamilic
    ContributorAuthor

    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

  3. fbricon commented on Mar 13, 2024

    @fbricon
    Collaborator

    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.

  4. mamilic commented on Mar 13, 2024

    @mamilic
    ContributorAuthor

    Thank you for explanation. Just curious, what would be your approach finding and removing unused public methods, fields, enums from code?

  5. fbricon commented on Mar 13, 2024

    @fbricon
    Collaborator

    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.

  6. mamilic commented on Mar 14, 2024

    @mamilic
    ContributorAuthor

    Thnank you for suggestions.

  7. bigunyak commented on Mar 22, 2026

    @bigunyak

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions