vscode插件数据格式基于json,sublime插件数据格式基于xml。sublime插件的官方文档说的不清楚,相关教程也很难找,遇到的一些坑记录一下
语法定义文件对比
同样使用TextMate定义(tmLanguage),sublime可读取的是xml格式,使用plist结构,极其坑爹
vscode: test.tmLanguage.json
{
"name": "Test",
"scopeName": "source.test",
"fileTypes": [
"test"
],
"patterns": [
{"include": "#comments"},
],
"repository": {
"comments": {
"match": "//.*",
"name": "comment.line.double-slash"
}
}
}
sublime: test.tmLanguage
uuid
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
name
Test
scopeName
source.test
fileTypes
test
patterns
include
#comments
repository
comments
match
//.*
name
comment.line.double-slash
- 格式区别: sublime提供一种单独的
sublime-syntax
格式,使用YAML格式编写,没试过。sublime提供了一种安装PackageDev
后,使用YAML编写"*.YAML-tmLanguage"文件,再生成XML文件的格式,但在有一定限制需要手写的时候不太好用。因为使用xml,支持多行文本(vscode的json中使用字符串列表),字符串不需要使用双引号包围,也不需要''转义 - 生效区别: vscode的语法文件需要在
package.json
中正确配置,sublime的语法定义文件直接塞到Packages
文件夹就可以生效。但有一点需要注意的是sublime需要uuid
字段来识别文件...因为这个问题纠结了一段比较长的时间
代码段定义对比
vscode
test.json 或 test.code-snippets
{
"snippet1": {
"scope": "source.test",
"prefix": "header",
"body": [
"this is a header.",
"this is the 2nd line."
]
},
"snippet2": {
"scope": "source.test",
"prefix": "header2",
"body": [
"this is a header 2.",
"this is the 2nd line."
]
}
}
sublime
header.sublime-snippets
source.proto
header
this is a header.
this is the 2nd line.
header2.sublime-snippets
source.proto
header2
this is a header 2.
this is the 2nd line.
二者的文件后缀名似乎都没什么限制。
sublime的代码段定义文件默认好像是只会读取第一个
片段,有多个代码段需要建立多个文件,没有深入研究是否有一个文件定义多个代码段的形式