дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
feat(plugins): expose database table menus and read-only schema (#7372)
Plugin API 1.20 adds wit/database.wit with describe-table behind the database.schema capability: a read-only view of a connected source's table (columns, keys, indexes) through DbManager::connected_table_details. Plugins can contribute database.table.context menu entries (needs_api 20) that receive the non-secret table identity and the when keys databaseDriver, databaseObjectKind, databaseSchema, databaseTable and databaseSelectionCount. Co-authored-by: gejun123456 <[email protected]>
Цей коміт міститься в:
1 джерело
abc5b2b2c6
коміт
b7c2d4eacb
201 files changed
+1180
-176
No files matched your search
@@ -69,6 +69,7 @@ Later:
|
||||
| `net:ask` | Medium | Ask the user at the first request to an HTTPS host that isn't declared | 1.5 |
|
||||
| `net.http:<host>` | Medium | Unencrypted HTTP to that host | 1.4 |
|
||||
| `database.sources` | Medium | Manage only the plugin's own project database sources and write their credentials; trusted projects only | 1.4 |
|
||||
| `database.schema` | Medium | Read table schema from connected project data sources, including user-created sources; trusted projects only. No credentials or row data. | 1.20 |
|
||||
| `fs.read:<path>` | High | `host::fs` reads outside the projects, under that path | 1.0 (the `fs` interface: 1.3) |
|
||||
| `fs.write:<path>` | High | `host::fs` writes outside the projects, under that path; does not imply reading | 1.3 |
|
||||
| `process:<program>` | High | Run that program: `run_process`, `run_command`, `start`, terminals, language servers, debug adapters, runs | 1.0 |
|
||||
|
||||
@@ -6,8 +6,9 @@ description: "Create and manage plugin-owned data sources in the Database tool w
|
||||
A plugin that starts or knows about a database (a local dev stack, a cloud tool, a
|
||||
container runner) can add a data source to the project's **Database** tool window, so the
|
||||
user doesn't have to type the connection settings. The plugin manages only the sources it
|
||||
created; it never sees user-created sources, other plugins' sources or any stored
|
||||
password. Once a source exists, the user works with it through the normal
|
||||
created through `database.sources`; it never reads stored passwords. API 1.20
|
||||
adds a separate `database.schema` permission for reading table metadata from connected
|
||||
project data sources, including user-created sources. Once a source exists, the user works with it through the normal
|
||||
[Database tools](/en/guide/database).
|
||||
|
||||
This is the `database` host interface (`database.wit`, API 1.4).
|
||||
@@ -103,3 +104,84 @@ seconds, and the call can be cancelled.
|
||||
|
||||
The [`data-tools` fixture](https://github.com/l0ng-ai/openidea/tree/main/crates/ide-plugin/tests/fixtures/data-tools)
|
||||
calls every function from commands.
|
||||
|
||||
## Table menus and schema inspection (API 1.20)
|
||||
|
||||
A code generator can contribute commands to `database.table.context`. The menu is
|
||||
available on table, view and materialized-view nodes. An optional `when` expression
|
||||
must match every selected table. Mixed selections containing folders or columns do
|
||||
not show these commands. Right-clicking outside the selection targets that table alone.
|
||||
|
||||
```toml
|
||||
engines.openidea = "^1.20"
|
||||
|
||||
[capabilities]
|
||||
required = ["project.read"]
|
||||
optional = ["database.schema", "project.write"]
|
||||
|
||||
[[contributes.commands]]
|
||||
id = "generate"
|
||||
title = "Generate mapper"
|
||||
|
||||
[[contributes.menus]]
|
||||
menu = "database.table.context"
|
||||
command = "generate"
|
||||
when = "databaseObjectKind == table"
|
||||
```
|
||||
|
||||
The command argument is a JSON string with `tables`, in selection order:
|
||||
|
||||
```json
|
||||
{
|
||||
"tables": [
|
||||
{
|
||||
"sourceId": "pg:inventory",
|
||||
"catalog": null,
|
||||
"schema": "public",
|
||||
"table": "users",
|
||||
"kind": "table",
|
||||
"driver": "postgres"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`sourceId` is an opaque host identifier; pass it back unchanged. `catalog` is
|
||||
present for catalog-aware tables (for example, attached DuckDB databases).
|
||||
The menu provides `databaseDriver`, `databaseObjectKind` (`table`, `view`,
|
||||
`materializedView`), `databaseSchema`, `databaseTable`, and
|
||||
`databaseSelectionCount` to `when`. These keys are local to this menu.
|
||||
|
||||
Read each selected table with the Rust SDK:
|
||||
|
||||
```rust
|
||||
use openidea_plugin::{DatabaseTableRef, Error, Invocation};
|
||||
|
||||
fn inspect(ctx: &Invocation, argument: &str) -> Result<(), Error> {
|
||||
let project = ctx.project().ok_or("Open a project first")?;
|
||||
let value: serde_json::Value = serde_json::from_str(argument)
|
||||
.map_err(|e| Error::Invalid(e.to_string()))?;
|
||||
let tables: Vec<DatabaseTableRef> = serde_json::from_value(value["tables"].clone())
|
||||
.map_err(|e| Error::Invalid(e.to_string()))?;
|
||||
for table in tables {
|
||||
let schema = project.database_table_schema(&table)?;
|
||||
// Generate files from schema.columns, schema.indexes and schema.foreign_keys.
|
||||
// Writing project files requires project.write separately.
|
||||
let _ = schema;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
`Project::database_table_schema` maps to WIT `database.describe-table(project, table)`.
|
||||
It returns the table comment; columns with type, nullability, default, primary-key
|
||||
flag and comment; indexes with uniqueness and column names; and foreign-key
|
||||
references. Availability and detail depend on the database driver.
|
||||
|
||||
Every call requires `database.schema` and a trusted, open project. This permission
|
||||
does not grant `database.sources`, and source ownership is not required. The source
|
||||
must already be connected through the Database tool window; inspection does not
|
||||
connect it or request credentials. No SQL execution, connection settings, passwords
|
||||
or row data are exposed. Requests respect cancellation and the host I/O deadline;
|
||||
missing or invisible tables fail, and each metadata collection is limited to 4096
|
||||
entries. Remote projects use the project's existing Database subsystem.
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: "API versions and compatibility"
|
||||
description: "engines.openidea, the plugin API versions from 1.0 to 1.19, and the rules that keep released plugins loading in newer IDEs."
|
||||
description: "engines.openidea, the plugin API versions from 1.0 to 1.20, and the rules that keep released plugins loading in newer IDEs."
|
||||
---
|
||||
|
||||
The plugin API has one version number: the version of the WIT package in [`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) (`openidea:plugin@1.19.0` on `main`). The host's engine version and the SDK's `API_VERSION` always agree with it, and the SDK carries an identical copy of the WIT files.
|
||||
The plugin API has one version number: the version of the WIT package in [`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) (`openidea:plugin@1.20.0` on `main`). The host's engine version and the SDK's `API_VERSION` always agree with it, and the SDK carries an identical copy of the WIT files.
|
||||
|
||||
<Note>
|
||||
The plugin system is a preview. The compatibility rules below hold for released 1.x versions; what is still unreleased
|
||||
@@ -34,6 +34,7 @@ The plugin API has one version number: the version of the WIT package in [`wit/`
|
||||
| 1.17.0 | OpenIDEA 0.1.53 | `decorations.set-styled`: editor decorations with their own `#rrggbb` / `#rrggbbaa` foreground and background, for colors outside the theme palette |
|
||||
| 1.18.0 | OpenIDEA 0.1.54 | `[[contributes.overlays]]`: a package web page floating over the workbench that never takes the keyboard focus, placed and resized through `openidea.overlay`; `[[contributes.dialogs]]`: a package web page in a modal, resizable IDE dialog opened with `views.reveal`, with a `closed` view event and `openidea.dialog.close()`; `events.subscribe-paths-with-options` (`debounce-ms`), `workspace.project.generation` and `FilesChanged` project/generation fields, stale run target/configuration rejection, and the `project-closed` lifecycle event; `execution-configurations`, `run.start-with-options` and `runDetectors.outputMode`: `pipes` or `pty` console output for plugin run configurations; `[[contributes.runAnything]]` with the `run-anything-provider` export: Run Anything lines starting with the plugin's prefix; `views.open-terminal-session-in`: a keyed terminal in a project directory; `workspace.invoking-project`: the project of the window a call serves, also in `gutter-actions` and `hover-actions`; `events.watch-paths` and the `watched-files-changed` event: files and directories outside the project, within `fs.read` grants; the `run-configuration-completion` export: completion in the Arguments field of the plugin's own run configurations; `services.context` and `services.toolbar` menus on the IDE's own Services nodes, with the selected services as the command argument; `executor` on `[[contributes.javaAgents]]`: "Run/Debug '<name>' with <title>" beside Run and Debug, the only launches that get that agent, also startable from the plugin's own commands with a configuration id; grant-scoped `agents.fork-session`: fork a recorded native agent session (`claude`, `codex`, or `copilot`) into a new task in the invoking window's project (`agents` capability), with the host validating the session and building the fork invocation itself |
|
||||
| 1.19.0 | In development on `main` | `[capabilities.reasons]`: the plugin's own sentence on why it asks for a capability, shown below the host's description in the permission dialog and Settings › Plugins; `settings.open` / `settings.open-permissions`: open Settings at one of the plugin's own pages or at its permissions; `net.fetch-stream`: a response whose body is read as it arrives (server-sent events, streamed model replies), with the SDK's `host::fetch_stream` and `sse` parser; `editor.open-as-text`: open a file in the built-in text editor even when a custom editor claims it (the SDK's `host::open_editor_as_text`); the `openIn` menu: the **Open In** submenu of the editor, its tab and the Project view |
|
||||
| 1.20.0 | In development | Database table context menus and read-only table schema inspection (`database.schema`). |
|
||||
|
||||
The full list of what each version added is in [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md).
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ optional = ["net:127.0.0.1", "clipboard.read"]
|
||||
| `net:ask` | 中 | 第一次请求未声明的 HTTPS 主机时询问用户 | 1.5 |
|
||||
| `net.http:<host>` | 中 | 通过未加密的 HTTP 访问该主机 | 1.4 |
|
||||
| `database.sources` | 中 | 只管理插件自己的项目数据源并写入其凭据;仅限受信任项目 | 1.4 |
|
||||
| `database.schema` | 中 | 读取已连接的项目数据源(包括用户创建的数据源)的表结构;仅限受信任项目,不返回凭据或表数据。 | 1.20 |
|
||||
| `fs.read:<path>` | 高 | 通过 `host::fs` 读取项目外、该路径下的文件 | 1.0(`fs` interface:1.3) |
|
||||
| `fs.write:<path>` | 高 | 通过 `host::fs` 写入项目外、该路径下的文件;不包含读权限 | 1.3 |
|
||||
| `process:<program>` | 高 | 运行该程序:`run_process`、`run_command`、`start`、终端、语言服务器、调试适配器、运行配置 | 1.0 |
|
||||
|
||||
@@ -4,8 +4,8 @@ description: "在数据库工具窗口中创建和管理插件自有的数据源
|
||||
---
|
||||
|
||||
如果插件会启动或知道某个数据库(本地开发环境、云工具、容器运行器等),可以把数据源直接加到项目的 **数据库**
|
||||
工具窗口中,省得用户手动填写连接设置。插件只能管理它自己创建的数据源:看不到用户创建的数据源、其他插件的数据源,
|
||||
也看不到任何已保存的密码。数据源创建后,用户就通过常规的 [数据库工具](/zh/guide/database) 使用它。
|
||||
工具窗口中,省得用户手动填写连接设置。`database.sources` 只能管理插件自己创建的数据源,无法读取已保存的密码。API 1.20 新增独立的
|
||||
`database.schema` 权限,用于读取已连接的项目数据源(包括用户创建的数据源)的表结构。数据源创建后,用户就通过常规的 [数据库工具](/zh/guide/database) 使用它。
|
||||
|
||||
这就是 `database` 宿主接口(`database.wit`,API 1.4)。
|
||||
|
||||
@@ -90,3 +90,59 @@ fn run_command(&mut self, _id: &str, ctx: &Invocation, _arg: Option<&str>) -> Re
|
||||
|
||||
[`data-tools` 测试插件](https://github.com/l0ng-ai/openidea/tree/main/crates/ide-plugin/tests/fixtures/data-tools)
|
||||
在命令中调用了全部函数。
|
||||
|
||||
## 表右键菜单与表结构读取(API 1.20)
|
||||
|
||||
代码生成插件可以向 `database.table.context` 添加命令,目标包括表、视图和物化视图节点。
|
||||
多选时,`when` 条件必须对每个节点都成立;选区混有文件夹或列时不显示插件菜单。
|
||||
右键点击选区之外的表时,仅以该表为目标。
|
||||
|
||||
```toml
|
||||
engines.openidea = "^1.20"
|
||||
|
||||
[capabilities]
|
||||
required = ["project.read"]
|
||||
optional = ["database.schema", "project.write"]
|
||||
|
||||
[[contributes.commands]]
|
||||
id = "generate"
|
||||
title = "生成 Mapper"
|
||||
|
||||
[[contributes.menus]]
|
||||
menu = "database.table.context"
|
||||
command = "generate"
|
||||
when = "databaseObjectKind == table"
|
||||
```
|
||||
|
||||
命令收到 JSON 字符串参数,`tables` 按选中顺序排列:
|
||||
|
||||
```json
|
||||
{
|
||||
"tables": [
|
||||
{
|
||||
"sourceId": "pg:inventory",
|
||||
"catalog": null,
|
||||
"schema": "public",
|
||||
"table": "users",
|
||||
"kind": "table",
|
||||
"driver": "postgres"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`sourceId` 是不透明的宿主标识,调用接口时原样传回。`catalog` 用于区分支持 catalog 的表,
|
||||
例如 DuckDB 的附加数据库。菜单的局部条件键为 `databaseDriver`、`databaseObjectKind`
|
||||
(`table`、`view`、`materializedView`)、`databaseSchema`、`databaseTable` 和
|
||||
`databaseSelectionCount`。
|
||||
|
||||
将 `tables` 反序列化为 `Vec<openidea_plugin::DatabaseTableRef>`,逐个调用
|
||||
`ctx.project().ok_or("请打开项目")?.database_table_schema(&table)`。
|
||||
Rust SDK 对应的 WIT 函数是 `database.describe-table(project, table)`。
|
||||
返回表注释,列的名称、类型、可空性、默认值、主键标记和注释,以及索引和外键引用。
|
||||
具体元数据取决于数据库驱动。写入生成文件仍需要单独的 `project.write` 权限。
|
||||
|
||||
每次调用都需要 `database.schema` 和受信任的已打开项目;它不授予 `database.sources`,
|
||||
也不要求数据源归插件所有。数据源必须已通过数据库工具窗口连接:接口不会自动连接或请求凭据,
|
||||
不提供 SQL 执行、连接设置、密码或行数据。调用支持取消并遵守宿主 I/O 超时;不存在或不可见的表
|
||||
会返回错误,每类元数据最多 4096 项。远程项目使用项目现有的数据库子系统。
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: "API 版本与兼容"
|
||||
description: "engines.openidea、插件 API 从 1.0 到 1.19 的各个版本,以及让已发布插件在新 IDE 中继续加载的规则。"
|
||||
description: "engines.openidea、插件 API 从 1.0 到 1.20 的各个版本,以及让已发布插件在新 IDE 中继续加载的规则。"
|
||||
---
|
||||
|
||||
插件 API 只有一个版本号:[`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) 中 WIT 包的版本(`main` 上是 `openidea:plugin@1.19.0`)。宿主的引擎版本和 SDK 的 `API_VERSION` 始终与它一致,SDK 里也带着一份完全相同的 WIT 文件。
|
||||
插件 API 只有一个版本号:[`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) 中 WIT 包的版本(`main` 上是 `openidea:plugin@1.20.0`)。宿主的引擎版本和 SDK 的 `API_VERSION` 始终与它一致,SDK 里也带着一份完全相同的 WIT 文件。
|
||||
|
||||
<Note>插件系统目前是预览版。下面的兼容规则适用于已发布的 1.x 版本;`main` 上尚未发布的内容在发布前仍可能变化。</Note>
|
||||
|
||||
@@ -31,6 +31,7 @@ description: "engines.openidea、插件 API 从 1.0 到 1.19 的各个版本,
|
||||
| 1.17.0 | OpenIDEA 0.1.53 | `decorations.set-styled`:自带 `#rrggbb` / `#rrggbbaa` 前景色和背景色的编辑器装饰,用于主题调色板之外的颜色 |
|
||||
| 1.18.0 | OpenIDEA 0.1.54 | `[[contributes.overlays]]`:悬浮在工作台上方、从不抢占键盘焦点的插件网页,可通过 `openidea.overlay` 移动和调整大小;`[[contributes.dialogs]]`:插件网页显示在可调整大小的模态对话框中,用 `views.reveal` 打开,关闭时发 `closed` 视图事件,页面可调用 `openidea.dialog.close()`;`events.subscribe-paths-with-options`(`debounce-ms`)、`workspace.project.generation` 与 `FilesChanged` 的 `project`/`generation` 字段、过期运行目标/配置拒绝以及 `project-closed` 生命周期事件;`execution-configurations`、`run.start-with-options` 与 `runDetectors.outputMode`:插件运行配置的控制台输出方式(`pipes` 或 `pty`);`[[contributes.runAnything]]` 与 `run-anything-provider` 导出:以插件前缀开头的 Run Anything 行;`views.open-terminal-session-in`:在项目子目录中打开带 key 的终端;`workspace.invoking-project`:本次调用所服务窗口的项目,`gutter-actions` 和 `hover-actions` 中也可用;`events.watch-paths` 与 `watched-files-changed` 事件:监听项目之外、`fs.read` 授权范围内的文件和目录;`run-configuration-completion` 导出:补全插件自己运行配置的“实参”字段;`services.context` 和 `services.toolbar` 菜单:作用于 IDE 自带的 Services 节点,命令参数是选中的服务;`[[contributes.javaAgents]]` 的 `executor`:运行和调试旁边的“使用 <title> 运行/调试 '<name>'”,只有经它启动时才加载该代理,插件自己的命令也可用配置 id 经它启动;需授权的 `agents.fork-session`:把录制的原生 agent 会话(`claude`、`codex` 或 `copilot`)派生为调用窗口项目中的新任务(`agents` 能力),宿主自行校验会话并构造 fork 调用 |
|
||||
| 1.19.0 | `main` 上开发中 | `[capabilities.reasons]`:插件用一句话说明为什么需要某个能力,显示在授权对话框和 设置 › 插件 中宿主说明的下方;`settings.open` / `settings.open-permissions`:打开设置并定位到插件自己的页面或它的权限;`net.fetch-stream`:边到达边读取响应体(服务器推送事件 SSE、模型的流式回复),SDK 提供 `host::fetch_stream` 和 `sse` 解析器;`editor.open-as-text`:即使文件被自定义编辑器认领,也用内置文本编辑器打开(SDK 的 `host::open_editor_as_text`);菜单点 `openIn`:编辑器、标签页和项目视图的 **打开方式** 子菜单 |
|
||||
| 1.20.0 | `main` 上开发中 | Database table context menus and read-only table schema inspection (`database.schema`). |
|
||||
|
||||
每个版本新增内容的完整列表见 [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md)。
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача