Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize comment block characters in visual studio code?

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

Has anyone already done or know how to do it?

like image 229
André Junges Avatar asked Jan 16 '16 01:01

André Junges


People also ask

How do you comment a block of code in VS code?

Comment Code Block Ctrl+K+C/Ctrl+K+U If you select a block of code and use the key sequence Ctrl+K+C, you'll comment out the section of code.


1 Answers

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

1 - CONFIG FILE

I dont know why it's not in the docs (or at least I couldn't find it) but there is a optional property you pass to the object inside the contributes.languages array in the package.json named configuration.

The description found on the vs code source code:

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

On that files you can create an object like this one and it's gonna overwrite the default comment characters

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

You can see this properties on the API references: https://code.visualstudio.com/Docs/extensionAPI/vscode-api#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 https://code.visualstudio.com/Docs/customization/keybindings

2 - "SYNTAX" FILE .tmLanguage

Yes, you can do it from there too and you can make it even better. You can see an example here https://github.com/andrejunges/vscode-handlebars/blob/master/syntaxes/handlebars.tmLanguage#L68

like image 130
André Junges Avatar answered Oct 16 '22 13:10

André Junges