我正在尝试在Visual Studio Code中创建扩展,以便为自定义语言启用语法突出显示。我在这里找到了@Wosi提供的有用建议:Create Custom Language in Visual Studio Code。基于此,我尝试了以下测试。我在%USERPROFILE%\.vscode\extensions
下创建了一个子文件夹,根目录中的package.json
定义如下(来自上面的示例):
{
"name": "mylang",
"version": "0.0.1",
"engines": {
"vscode": ">=0.9.0-pre.1"
},
"publisher": "me",
"contributes": {
"languages": [{
"id": "mylang",
"aliases": ["MyLang", "mylang"],
"extensions": [".mylang",".myl"]
}],
"grammars": [{
"language": "mylang",
"scopeName": "source.mylang",
"path": "./syntaxes/mylang.tmLanguage"
}]
}
}
然后我在其下创建了一个语法子文件夹,并根据@wozi给出的示例包含了一个mylang.tmLanguage
文件:How to create a simple custom language colorization to VS Code只需要进行一些小修改,只需使命名与在JSON文件之上:
<?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>scopeName</key>
<string>source.mylang</string>
<key>fileTypes</key>
<array>
<string>mylang</string>
<string>myl</string>
</array>
<key>name</key>
<string>mylang file</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\b(?i:(hint|info|information))\b</string>
<key>name</key>
<string>info-token</string>
</dict>
<dict>
<key>match</key>
<string>\b(?i:(warning|warn))\b</string>
<key>name</key>
<string>warn-token</string>
</dict>
<dict>
<key>match</key>
<string>\b(?i:(Error|Failure|Fail))\b</string>
<key>name</key>
<string>error-token</string>
</dict>
<dict>
<key>match</key>
<string>\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b</string>
<key>name</key>
<string>constant.numeric</string>
</dict>
</array>
<key>uuid</key>
<string>FF0550E0-3A29-11E3-AA6E-0800200C9A77</string>
</dict>
</plist>
但是,当我使用以下测试文件(test.mylang
)打开Visual Studio代码(v1.11.2)时:
2017-04-17 18:38 Hint This should be blue!
2017-04-17 18:38 Warning This should be amber!
2017-04-17 18:38 Fail This should be red!
关键字没有颜色(提示,警告,失败)。我是否需要做其他事情来指定主题?或者我是否需要指定一个新的唯一UUID(如果是,我可以自己编写,还是需要以某种方式注册)?