Search code examples
javavisual-studio-codesyntax-highlightingdeprecated

Deprecated Java methods not showing as strikethrough in Visual Studio Code


I have this Java method:

/**
 * Old method is deprecated.
 * @deprecated Use {@link #newMethod()} instead.
 * @return boolean
 */
@Deprecated
public static boolean oldMethod() {
  return false;
}

and then later on:

boolean result = oldMethod();

In the VS Code editor, the oldMethod() doesn't show with strikethough like it does in the NetBeans (and other decent IDEs). Oddly, it does show as strikethrough in the popup code completion, but not in the final code.

I also tried calling the method from a different class, and it still has the same issue:

public class Class2 {
  void example() {
    Class1.oldMethod();
  }
}

I'm using the Apache NetBeans language server extension - however I have the same behaviour when using the ones from Oracle, Red Hat and Microsoft. Also, I checked the "Editor: Show Deprecated" setting and it is turned on. Why is it not shown?


Solution

  • I have also tested "editor.showDeprecated": true was not working for me.

    After playing around with VS Code configurations, I have found the solution.

    Solution: Update the .vscode/settings.json of your Java Project to have editor.semanticTokenColorCustomizations that you can use to do the customization on the semantics.

    Screenshot of the settings.json location that will be present in your project:

    enter image description here

    settings.json:

    {
      ......
    
      "editor.showDeprecated": true,
      "editor.suggest.showDeprecated": true,
      "editor.semanticTokenColorCustomizations": {
        "enabled": true,
        "rules": {
          "*.deprecated": { 
             "strikethrough": true
          }
        }
      }
    }
    

    Screenshot of the Java code:

    enter image description here

    As soon as you use @Deprecated annotation, it will put strikethrough.