2

When I create a class like below:

enter image description here

Visual Studio Code adds the comment with Java class name above the class. How do I disable it? I mean I don't need this comment to be added at all.

enter image description here

ata
  • 1,254
  • 1
  • 9
  • 30
  • You should not get rid of the comment, you should replace the classname with text to document your code. Even if the class at hand is a simple one, you can use `@see` constructs to guide readers. – rsp Mar 05 '20 at 09:31
  • Have you looked at https://stackoverflow.com/a/46904929/10785239 answer by @Darren? – I'm_Pratik Mar 05 '20 at 09:59
  • See https://stackoverflow.com/a/64688778/836330 and https://github.com/microsoft/vscode/issues/10565#issuecomment-721832613 if you want to disable snippets on a per-snippet basis. – Mark Nov 04 '20 at 22:47

2 Answers2

4

I'm going to assume you have the Language Support for Java(TM) by Red Hat plugin installed. This seems to be the plugin that adds the class code snippet, I tried disabling it and the snippet no longer showed up.

A solution might be to write your own snippet with the class prefix that doesn't have the comment you dislike. I looked into user-created snippets in VSCode and found these useful support docs: https://code.visualstudio.com/docs/editor/userdefinedsnippets

Here's how you accomplish this:

  1. Open your command palette (Ctrl Shift P / Cmd Shift P) and search for Preferences: Configure User Snippets
  2. Search for java.json
  3. Add this JSON object to the file (within the existing brackets):
"Class": {
    "prefix": "class",
    "body": [
        "public class ${TM_FILENAME_BASE} {",
        "\t$0",
        "}"
    ],
    "description": "Public class"
}

You can change the "prefix" to anything you'd like. If you add this snippet, you'll see you now have 2 snippets when you enter the class keyword. I'm not really sure how to fix this, except for changing the prefix.

Another tip: you can change "editor.snippetSuggestions" to "top" in your settings. This will put snippets at the top of the suggestion box. (From: https://stackoverflow.com/a/40129409/3235858)

I hope this helped you!

YSbakker
  • 697
  • 2
  • 8
  • 27
  • Thank you for your response. Unfortunately, it is the solution I want, however, that was helpful and I learnt how to create user snippets :) – ata Mar 05 '20 at 12:42
  • @SomeDev No problem. Could you maybe clarify what solution you are looking for? – YSbakker Mar 05 '20 at 13:27
  • Go to: `File` | `Preferences` | `User Snippets` and choose the json file you want to modify – rioV8 Mar 09 '20 at 15:26
  • @rioV8 yes, that has the same effect as doing it through the command palette – YSbakker Mar 09 '20 at 15:31
0

I think you are using some extension like Powershell. Go and disable or uninstall that extension and the problem will be automatically resolved.

Do check this link.

Thanks.