在VS Code中如何为JSON文件创建片段?

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月15日 00:13:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248501.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定