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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>uuid</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>name</key>
<string>Test</string>
<key>scopeName</key>
<string>source.test</string>
<key>fileTypes</key>
<array>
<string>test</string>
</array>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#comments</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>comments</key>
<dict>
<key>match</key>
<string>//.*</string>
<key>name</key>
<string>comment.line.double-slash</string>
</dict>
</dict>
</dict>
</plist>
- 格式區別: 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
<snippet>
<scope>source.proto</scope>
<tabTrigger>header</tabTrigger>
<content>this is a header.
this is the 2nd line.</content>
</snippet>
header2.sublime-snippets
<snippet>
<scope>source.proto</scope>
<tabTrigger>header2</tabTrigger>
<content>this is a header 2.
this is the 2nd line.</content>
</snippet>
二者的文件后綴名似乎都沒什么限制。
sublime的代碼段定義文件默認好像是只會讀取第一個<snippet>
片段,有多個代碼段需要建立多個文件,沒有深入研究是否有一個文件定義多個代碼段的形式