如何说服VS代码在JSON文件中接受#作为注释?
我们有一些特殊文件,其中包含与# comments
混合的JSON数据.
We have special files that contain JSON data mixed with # comments
.
我认为我需要使用以下方法增强Code的json.settings
文件:
I figured I need to enhance Code's json.settings
file with:
"files.associations": {
"*.ourextension": "jsonc"
}
,但随后我发现 jsconc
与
but then I discovered that jsconc
is about JSON data with // comments
.
是否有一种方便的方法来获取VS代码以接受JSON数据中的# comments
?
Is there a convenient way to get VS code to accept # comments
in JSON data?
VS代码可以识别jsconc
语言,它会向我显示此错误消息:
VS code recognizes the jsconc
language, it gives me this error message:
它也接受//
注释:
添加////给我第一行 green ,现在第二行得到第一个错误(因为以#开头).
adding the // got me a green first line, and now the second line gets the first error (because starting with #).
一个不同的答案:可能可以添加这样的新语言定义,但这需要大量工作.我还可以快速查看一下是否可以简单地为VS代码附带的jsonc
更改相应的json配置文件,但是该文件相当复杂,并且可能在下一次VS代码更新中被覆盖.
A distinct non-answer: it might be possible to add a such a new language definition, but it would require quite a bit of work. I also had a quick look if I could simply change the corresponding config json file for jsonc
that ships with VS code, but that file is rather complex, and would probably be overridden with the next VS code update.
因此,一种直接的解决方法.两个脚本将一种命令样式替换为另一种:
Thus a straight forward workaround. Two scripts to replace one command style with the other:
#!/bin/sh
# a helper script that turns all # into //
# with the syntax that works for sed on MAC OS
for file in "$@"
do
sed -i '' -e 's,#,//,g' $file
done
考虑到我们的特定要求,并不完全方便,但快速而强大.
Not exactly convenient, but fast and robust, given our specific requirements.