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]>
Цей коміт міститься в:
葛俊таgejun123456 authored and GitHub committed 2026-12-02 14:25:35 +08:00
1 джерело abc5b2b2c6
коміт b7c2d4eacb
201 files changed
+1180 -176

No files matched your search

+1
Переглянути файл
@@ -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 |
+84 -2
Переглянути файл
@@ -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.
+3 -2
Переглянути файл
@@ -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).