plugin.yaml 贡献点参考
Dart 扩展在 plugin.yaml 中通过 contributes 声明命令、快捷键、视图容器等,类似 VS Code 的 Contribution Points。
contributes.commands
声明可在命令面板中调用的命令。
| 字段 | 必填 | 说明 |
|---|---|---|
| id | 是 | 唯一标识,如 `my_plugin.hello` |
| title | 是 | 命令面板显示名称 |
| category | 否 | 分组,如 `My Plugin` |
yaml
contributes:
commands:
- id: my_plugin.hello
title: Say Hello
category: My Plugin
需在代码中通过 context.commands.registerCommand 注册回调,见 扩展指南:命令注册。
contributes.keybindings
为命令绑定快捷键。
| 字段 | 必填 | 说明 |
|---|---|---|
| command | 是 | 命令 id |
| key | 是 | 快捷键,如 `ctrl+shift+d` |
| when | 否 | 条件表达式(可选) |
yaml
contributes:
keybindings:
- command: my_plugin.hello
key: ctrl+shift+h
contributes.viewContainers
在侧边栏注册视图容器(Activity Bar 图标 + 侧边栏区域)。
| 字段 | 必填 | 说明 |
|---|---|---|
| sidebar | - | 侧边栏容器列表 |
| id | 是 | 容器 id |
| title | 是 | 显示标题 |
| icon | 否 | 图标名,如 `dashboard` |
| order | 否 | 排序(数字越小越靠前) |
yaml
contributes:
viewContainers:
sidebar:
- id: my_plugin
title: My Plugin
icon: dashboard
order: 80
contributes.views
在容器内注册视图,需与 viewContainers 的 id 对应。
| 字段 | 必填 | 说明 |
|---|---|---|
| id | 是 | 视图 id |
| name | 是 | 显示名称 |
| order | 否 | 排序 |
yaml
contributes:
views:
my_plugin:
- id: my_plugin.overview
name: Overview
order: 0
configuration
插件可配置项,在 IDE 设置中可编辑。
| 字段 | 必填 | 说明 |
|---|---|---|
| key | 是 | 配置键,如 `my_plugin.interval` |
| type | 是 | string | integer | boolean | filePath |
| description | 否 | 说明 |
| default | 否 | 默认值 |
通过 context.workspace.getConfiguration('my_plugin.interval') 读取。
activationEvents
控制插件何时激活。
| 值 | 说明 |
|---|---|
* | 应用启动时激活 |
onView:viewId | 打开指定视图时激活 |
onCommand:commandId | 执行命令时激活 |
onLanguage:languageId | 打开对应语言文件时激活 |
permissions
声明插件所需权限,见 插件清单。