外观
编辑器支持
为了方便开发,我们针对 Visual Studio Code 专门编写了一些代码片段(snippet),可以用于加速开发。这些代码片段定义在 .vscode/*.code-snippets 文件中,用 VS Code 打开项目时,编辑器会自动读取这些代码片段。之后你就可以通过键盘输入 prefix 字段定义的前缀,来触发对应的代码片段。
提示
你可以参考现有的例子自行添加其他代码片段定义。定义规则如下:
scope:指定代码片段的作用范围,例如typescript、javascript等。若同时支持多个作用范围,用英文逗号隔开。prefix:指定代码片段的触发前缀,例如createTableIfNotExist。description:指定代码片段的描述,例如Create table if not exist。body:指定代码片段的内容,支持变量替换。
示例:
json
{
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": ["console.log('$1');", "$2"],
"description": "Log output to console"
}
}1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
预置的代码片段
createTable
创建数据库表(如果不存在)
json
{
"createTableIfNotExist": {
"scope": "typescript",
"prefix": "createTable",
"description": "Create table if not exist",
"body": [
"import { createTableIfNotExist } from \"#scripts/DatabaseUtils\";",
"",
"// ${1:创建表(如果不存在)}",
"export async function createTable${2:大写表名}IfNotExist(): Promise<void> {",
" await createTableIfNotExist({",
" tableName: '${3:下划线连接的小写表名}',",
" createTable: (table) => {",
" ${4:// table.integer(\"user_id\").unsigned().references(\"user.id\");}",
" },",
" afterCreated: async (${5:knex}) => {",
" ${6:// do something after created table}",
" },",
" });",
"}"
]
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23