Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vscode extensions - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...