20

I created a language extension for Visual Studio Code and I would like to change the comment block characters, but I couldn't find a way to do so..

How can I do it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
André Junges
  • 5,297
  • 3
  • 34
  • 48

2 Answers2

25

OK, I finally figured out what the problem was. There are two ways you can change the comment blocks:

1. Configuration file

I don’t know why it's not in the documentation (or at least I couldn't find it), but there is an optional property you pass to the object inside the contributes.languages array in the package.json file named configuration.

The description found on the Visual Studio Code source code:

A relative path to a file containing configuration options for the language.

In those files you can create an object like this one and it's going to overwrite the default comment characters

{
  "comments": {
    "lineComment": "//",
    "blockComment": [ "<!--", "-->" ]
  }
}

You can see this properties on the API references: CommentRule

Note: That comment block command is triggered with a different shortcut. You can overwrite it though (in a general or even for a specific language using the property when on the key binding object).

⇧⌥A - Toggle Block Comment - editor.action.blockComment

Key Bindings for Visual Studio Code

2. "Syntax" file .tmLanguage

Yes, you can do it from there too and you can make it even better. You can see an example on vscode-handlebars/syntaxes/handlebars.tmLanguage.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
André Junges
  • 5,297
  • 3
  • 34
  • 48
  • 7
    Where ist this 'package.json' stored? – Mehrdad Mirreza Feb 11 '20 at 09:57
  • 4
    For me, the file was located (mac OS): /Users/USERNAME/.vscode/extensions/EXTENSION_NAME/language-configuration.json – Samuel Segal Apr 02 '20 at 18:56
  • How to get rid of the auto inserted asterisk in block comments? I don't want any asterisks just /** .... */ Thank you. – Meryan Feb 22 '21 at 06:02
  • What's the extension name for typescript? – Adrian Gonzalez Dec 20 '21 at 03:27
  • @Meryan This is a good question, did you start a separate thread on it? – oxwilder Jan 21 '22 at 15:33
  • @oxwilder I believe I captured my frustration with these asterisks here Please pitch in your vote and insgihts https://stackoverflow.com/questions/70309428/how-can-i-configure-jsdoc-or-vscode-to-not-use-leading-star-asterix-in-block-com – Meryan Jan 21 '22 at 19:23
  • For windows, the file is located at: `C:\Users\USERNAME\.vscode\extensions\EXT_NAME` It might also be at: `C:\Users\USERNAME\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions` – Kay May 25 '22 at 11:51
  • No joy on 27-Oct-2022 on Windows 10 Pro. I don't find any of these files or settings. – Tom Stambaugh Oct 27 '22 at 16:55
-1

Try deleting the Babel extension if you are using the Visual Studio Code editor. It worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131