安装脚手架
npm install -g yo generator-code
生成插件模板
yo code
配置语言支持
我这里就自定义一种以.da
结尾的语言,修改根目录下的package.json
文件的contributes
处的属性
{
"contributes": {
"languages": [
{
"id": "da",
"aliases": [
"DA"
],
"extensions": [
".da"
],
"icon": {
"dark": "logo.png",
"light": "logo.png"
},
"configuration": "language.json"
}
],
"grammars": [
{
"language": "da",
"scopeName": "source.da",
"path": "grammars.json"
}
],
"snippets": [
{
"language": "da",
"path": "snippets.json"
}
],
}
}
自动补全括号、注释
在根目录创建language.json
文件,填入以下内容,该文件是用来自动补全括号,单行和多行注释用什么符号,我这里注释用-
{
"comments": {
"blockComment": [
"---",
"---"
],
"lineComment": "-"
},
"brackets": [
[
"(",
")"
],
[
"[",
"]"
],
[
"{",
"}"
]
],
"autoClosingPairs": [
[
"(",
")"
],
[
"[",
"]"
],
[
"{",
"}"
]
],
"surroundingPairs": [
[
"(",
")"
],
[
"[",
"]"
],
[
"{",
"}"
]
]
}
语言高亮
在根目录创建grammars.json
文件,填入以下内容patterns
里面对应repository
里面的内容patterns.match
就是匹配规则,颜色的话我也没怎么研究明白,交给你们研究了
{
"name": "da",
"scopeName": "source.da",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#strings"
},
{
"include": "#numbers"
},
{
"include": "#comments"
},
{
"include": "#variables"
},
{
"include": "functions"
}
],
"repository": {
"keywords": {
"patterns": [
{
"name": "keyword.control.da",
"match": "\\b(?:def|print|class|if|for|while|do)\\b"