英文:
How to make snippets for json files in VS Code?
问题
VS Code使用JSON文件创建代码片段。要为JSON文件创建代码片段,您需要在JSON文件中编写如下内容:
{
"snippety": {
"prefix": "snippet",
"body": [
"$1: {",
" \"prefix\": \"$2\",",
" \"body\": [",
" \"$3\"",
" ],",
" \"description\": \"$4\"",
"}"
],
"description": "wow"
}
}
但是,该代码片段可能不会出现在建议列表中。
英文:
VS code uses JSON files to make snippets. So to make make snippets for a JSON File you need to write in an JSON file.
So, I tried it. This:
{
"snippety":{
"prefix": "snippet",
"body": [
"\"$1\":{",
"\t\"prefix\": \"$2\",",
"\t\"body\":[",
"\t\t\"$3\"",
"\t],",
"\t\"description\":\"$4\""
],
"description": "wow"
}
}
But the snippet won't come in the suggestion list.
答案1
得分: 1
将你的片段放入名为 jsonc.json
的片段文件中(你可以使用“齿轮”图标/用户片段选择器创建它,选择 jsonc
),然后它将起作用。
你尝试在的片段文件是 jsonc
文件,而不是 json
文件。
英文:
Put your snippet into the jsonc.json
snippets file (that you create with the Gear icon/User Snippets picker with jsonc
) and then it will work.
The snippets files you are trying to use the snippet in are jsonc
files, not json
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论