diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index e741d11ea..a3008e9ae 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -1355,6 +1355,25 @@ impl DbManager { Self::table_details_on(&pool, Some(catalog), schema, table).await } + /// Read metadata using an existing connection only. A concurrent disconnect must not + /// cause a read-only extension request to reopen a source or prompt for credentials. + pub async fn connected_table_details( + &self, + id: &str, + catalog: Option<&str>, + schema: &str, + table: &str, + ) -> IdeResult { + if catalog.is_some() { + let source = self.source(id)?; + if id != source.id || source.driver != DbDriver::Jdbc || source.vendor != "duckdb" { + return Err(IdeError::invalid("Catalog browsing requires a DuckDB data source")); + } + } + let pool = self.connected_pool(id)?; + Self::table_details_on(&pool, catalog, schema, table).await + } + pub async fn table_details(&self, id: &str, schema: &str, table: &str) -> IdeResult { let pool = self.pool(id).await?; Self::table_details_on(&pool, None, schema, table).await diff --git a/crates/ide-db/src/route.rs b/crates/ide-db/src/route.rs index 17e75d9b6..4a1c7917a 100644 --- a/crates/ide-db/src/route.rs +++ b/crates/ide-db/src/route.rs @@ -165,6 +165,17 @@ impl DbManager { .collect() } + /// Snapshot an existing connection without allocating a slot or opening a route. + pub(super) fn connected_pool(&self, id: &str) -> IdeResult> { + self.pools + .lock() + .get(id) + .and_then(|slot| slot.value.get()) + .filter(|connection| !connection.is_closed()) + .map(|connection| connection.pool.clone()) + .ok_or_else(|| IdeError::invalid("Connect the data source in the Database tool window first")) + } + pub async fn pool(&self, id: &str) -> IdeResult> { Ok(self.connection(id).await?.pool) } diff --git a/crates/ide-extension/src/capability.rs b/crates/ide-extension/src/capability.rs index 8594ba846..15f1c2f32 100644 --- a/crates/ide-extension/src/capability.rs +++ b/crates/ide-extension/src/capability.rs @@ -24,6 +24,8 @@ pub enum Capability { IdeCommands, /// Manage only its own project database sources and write their credentials. DatabaseSources, + /// Read table metadata of connected project sources; never rows or credentials. + DatabaseSchema, VcsRead, VcsWrite, /// The Maven / Gradle dependency graph the IDE resolved. @@ -93,6 +95,7 @@ impl Capability { } Self::EditorWrite | Self::DatabaseSources + | Self::DatabaseSchema | Self::VcsWrite | Self::Net(_) | Self::NetAsk @@ -130,6 +133,7 @@ impl Capability { Self::EditorWrite => "Change text in the editor".into(), Self::ProjectWrite => "Create and change files in the open project".into(), Self::DatabaseSources => "Manage its own database sources and store their passwords in trusted projects".into(), + Self::DatabaseSchema => "Read table structures of connected database sources in trusted projects, without rows or passwords".into(), Self::IdeCommands => "Run any IDE action or other plugins' commands as if you chose them, including running programs, committing and pushing".into(), Self::VcsRead => "Read version control state".into(), Self::VcsWrite => "Change version control state (commit, fetch, checkout)".into(), @@ -289,6 +293,7 @@ impl fmt::Display for Capability { Self::ProjectWrite => f.write_str("project.write"), Self::IdeCommands => f.write_str("ide.commands"), Self::DatabaseSources => f.write_str("database.sources"), + Self::DatabaseSchema => f.write_str("database.schema"), Self::VcsRead => f.write_str("vcs.read"), Self::VcsWrite => f.write_str("vcs.write"), Self::BuildRead => f.write_str("build.read"), @@ -383,6 +388,7 @@ impl FromStr for Capability { "project.write" => Self::ProjectWrite, "ide.commands" => Self::IdeCommands, "database.sources" => Self::DatabaseSources, + "database.schema" => Self::DatabaseSchema, "vcs.read" => Self::VcsRead, "vcs.write" => Self::VcsWrite, "build.read" => Self::BuildRead, @@ -677,6 +683,23 @@ mod net_setting_tests { mod database_tests { use super::*; #[test] + fn database_schema_is_a_separate_medium_risk_grant_requiring_api20() { + let cap: Capability = "database.schema".parse().unwrap(); + assert_eq!(cap, Capability::DatabaseSchema); + assert_eq!(cap.to_string(), "database.schema"); + assert_eq!(cap.risk(), Risk::Medium); + assert!(!cap.auto_migrates()); + for other in [Capability::ProjectRead, Capability::DatabaseSources] { + assert!(!other.covers(&cap)); + } + for (api, valid) in [("^1.19", false), ("^1.20", true)] { + let text = format!( + "id='schema'\nname='Schema'\nversion='1.0.0'\nengines.openidea='{api}'\n[capabilities]\nrequired=['database.schema']" + ); + assert_eq!(crate::Manifest::parse(&text).is_ok(), valid); + } + } + #[test] fn database_sources_is_a_medium_risk_exact_grant_requiring_api4() { let cap: Capability = "database.sources".parse().unwrap(); assert_eq!(cap, Capability::DatabaseSources); diff --git a/crates/ide-extension/src/manifest.rs b/crates/ide-extension/src/manifest.rs index 6f84a6557..7885bfeaf 100644 --- a/crates/ide-extension/src/manifest.rs +++ b/crates/ide-extension/src/manifest.rs @@ -34,7 +34,7 @@ use std::path::{Component, Path, PathBuf}; pub const MANIFEST_FILE: &str = "plugin.toml"; /// The plugin API (engine) version this host implements. -pub const ENGINE_VERSION: &str = "1.19.0"; +pub const ENGINE_VERSION: &str = "1.20.0"; /// The longest `[capabilities.reasons]` entry, in characters: a sentence or two. pub const MAX_CAPABILITY_REASON: usize = 500; /// The 0.1 API, still accepted for contribution-only packages and 0.1 components. @@ -426,6 +426,9 @@ impl Manifest { if matches!(cap, Capability::ClipboardRead) { self.needs_api(&format!("capability `{cap}`"), 11)?; } + if matches!(cap, Capability::DatabaseSchema) { + self.needs_api(&format!("capability `{cap}`"), 20)?; + } if matches!(cap, Capability::Agents) { self.needs_api(&format!("capability `{cap}`"), 18)?; } diff --git a/crates/ide-host/src/plugins/api.rs b/crates/ide-host/src/plugins/api.rs index f7240a54d..52d90926d 100644 --- a/crates/ide-host/src/plugins/api.rs +++ b/crates/ide-host/src/plugins/api.rs @@ -1746,6 +1746,31 @@ impl PluginApi { } impl HostApi for PluginApi { + fn database_table_schema( + &self, + root: &Path, + client: Option<&str>, + table: &ide_plugin::PluginDatabaseTableRef, + cancel: &CancellationToken, + timeout: Duration, + ) -> Result { + self.require_api("database table schema", 20)?; + let (host, fallback) = self.database_host(root)?; + // Connections belong to windows, even when several windows open the same root. + // Prefer the invoking window; background calls may use any connected instance. + let db = client + .and_then(|client| host.project(client).ok()) + .filter(|project| project.root == root) + .map(|project| project.db.clone()) + .or_else(|| { + host.projects() + .into_iter() + .find(|project| project.root == root && project.db.is_connected(&table.source_id)) + .map(|project| project.db.clone()) + }) + .unwrap_or(fallback); + host.runtime.block_on(super::database::table_schema(&db, table, cancel, timeout)) + } fn database_upsert(&self, root: &Path, source: ide_plugin::PluginDataSource) -> Result<(), HostError> { let (host, db) = self.database_host(root)?; let id = source.id.clone(); diff --git a/crates/ide-host/src/plugins/database.rs b/crates/ide-host/src/plugins/database.rs index 5fb19ee11..96680020d 100644 --- a/crates/ide-host/src/plugins/database.rs +++ b/crates/ide-host/src/plugins/database.rs @@ -189,6 +189,70 @@ pub(super) fn error(e: IdeError) -> HostError { } } +/// Schema inspection is deliberately separate from ownership/credential management. +pub(super) async fn table_schema( + db: &ide_db::DbManager, + table: &ide_plugin::PluginDatabaseTableRef, + cancel: &CancellationToken, + timeout: Duration, +) -> Result { + if table.source_id.is_empty() + || table.table.is_empty() + || [&table.source_id, &table.schema, &table.table] + .into_iter() + .chain(table.catalog.iter()) + .any(|v| v.len() > 4096 || v.contains('\0')) + { + return Err(HostError::Invalid("invalid database table reference".into())); + } + if cancel.is_cancelled() { + return Err(HostError::Cancelled); + } + let read = db.connected_table_details(&table.source_id, table.catalog.as_deref(), &table.schema, &table.table); + let details = tokio::select! { + biased; + _ = cancel.cancelled() => return Err(HostError::Cancelled), + result = tokio::time::timeout(timeout, read) => result + .map_err(|_| HostError::Failed("Database schema request timed out".into()))?.map_err(error)?, + }; + if details.columns.is_empty() { + return Err(HostError::NotFound("table has no visible columns".into())); + } + if details.columns.len() > 4096 || details.indexes.len() > 4096 || details.foreign_keys.len() > 4096 { + return Err(HostError::Invalid("table schema exceeds 4096 columns, indexes or foreign keys".into())); + } + Ok(ide_plugin::PluginDatabaseTableSchema { + comment: details.comment, + columns: details + .columns + .into_iter() + .map(|c| ide_plugin::PluginDatabaseColumn { + name: c.name, + data_type: c.data_type, + nullable: c.nullable, + default_value: c.default, + primary_key: c.primary_key, + comment: c.comment, + }) + .collect(), + indexes: details + .indexes + .into_iter() + .map(|i| ide_plugin::PluginDatabaseIndex { name: i.name, unique: i.unique, columns: i.columns }) + .collect(), + foreign_keys: details + .foreign_keys + .into_iter() + .map(|f| ide_plugin::PluginDatabaseForeignKey { + columns: f.columns, + referenced_schema: f.ref_schema, + referenced_table: f.ref_table, + referenced_columns: f.ref_columns, + }) + .collect(), + }) +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ide-host/src/plugins/ui_points.rs b/crates/ide-host/src/plugins/ui_points.rs index ee990f7c2..78cafc377 100644 --- a/crates/ide-host/src/plugins/ui_points.rs +++ b/crates/ide-host/src/plugins/ui_points.rs @@ -119,7 +119,9 @@ const COMMIT_MESSAGE_MENU: &str = "commit.message"; const SERVICES_MENUS: [&str; 2] = ["services.context", "services.toolbar"]; /// The Open In › submenu of the editor, editor tab and project view menus: the command gets the file. const OPEN_IN_MENU: &str = "openIn"; -const MENU_IDS: [&str; 13] = [ +/// Context menu of tables/views in the Database tool window (API 1.20). +const DATABASE_TABLE_MENU: &str = "database.table.context"; +const MENU_IDS: [&str; 14] = [ "editor.context", "projectView.context", "editorTab.context", @@ -133,6 +135,7 @@ const MENU_IDS: [&str; 13] = [ SERVICES_MENUS[0], SERVICES_MENUS[1], OPEN_IN_MENU, + DATABASE_TABLE_MENU, ]; const MAX_TITLE: usize = 256; const MAX_SETTINGS: usize = 200; @@ -200,6 +203,9 @@ pub(super) fn menu(pkg: &Package, decl: toml::Value) -> Result { if SERVICES_MENUS.contains(&d.menu.as_str()) { pkg.manifest.needs_api(&format!("contributes.menus: {}", d.menu), 18)?; } + if d.menu == DATABASE_TABLE_MENU { + pkg.manifest.needs_api(&format!("contributes.menus: {DATABASE_TABLE_MENU}"), 20)?; + } if d.menu == OPEN_IN_MENU { pkg.manifest.needs_api(&format!("contributes.menus: {OPEN_IN_MENU}"), 19)?; } @@ -1372,6 +1378,20 @@ pub(super) fn locales(pkg: &Package, _decl: toml::Value) -> Result bool) -> bool { } false } + +#[tokio::test(flavor = "multi_thread")] +async fn schema_reads_user_tables_without_rows_or_credentials_and_enforces_grants() { + let f = Harness::with_timeout(Duration::from_secs(10)); + let table = + serde_json::json!({"sourceId":"user-source","catalog":null,"schema":"main","table":"users"}).to_string(); + assert!(f.run("table-schema", Some(&table)).is_err(), "untrusted projects are refused"); + f.host.set_project_trust(&f.root, true, false).await.unwrap(); + let db = f.host.project("main").unwrap().db.clone(); + db.save_sources(vec![ide_db::DataSource { + id: "user-source".into(), + name: "User-owned SQLite".into(), + driver: ide_db::DbDriver::Sqlite, + file: Some(f.root.join("db.sqlite").into()), + ..Default::default() + }]) + .await + .unwrap(); + assert!(f.run("table-schema", Some(&table)).is_err(), "inspection never connects implicitly"); + assert!(!db.is_connected("user-source")); + let cancel = CancellationToken::new(); + for sql in [ + "CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT NOT NULL DEFAULT 'guest', manager_id INTEGER REFERENCES users(id))", + "CREATE INDEX users_name ON users(name)", + "INSERT INTO users(name) VALUES ('private-row-value')", + ] { + db.execute("user-source", sql, 100, &cancel).await.unwrap(); + } + assert!(!f.host.project("second").unwrap().db.is_connected("user-source")); + assert!( + f.plugins + .run_command( + ID, + "table-schema", + Some(&table), + Invocation { client: Some("second".into()), ..f.invocation() } + ) + .is_err(), + "a disconnected window cannot borrow another window's connection" + ); + let response = f.run("table-schema", Some(&table)).unwrap().unwrap(); + let schema: serde_json::Value = serde_json::from_str(&response).unwrap(); + assert_eq!(schema["columns"][0]["name"], "id"); + assert_eq!(schema["columns"][0]["primaryKey"], true); + assert_eq!(schema["columns"][1]["nullable"], false); + assert_eq!(schema["columns"][1]["defaultValue"], "'guest'"); + assert!(schema["indexes"].as_array().unwrap().iter().any(|i| i["name"] == "users_name")); + assert!(schema["foreignKeys"].as_array().unwrap().iter().any(|k| k["referencedTable"] == "users")); + let menu_argument = serde_json::json!({ "tables": [{ + "sourceId": "user-source", "catalog": null, "schema": "main", "table": "users", + "kind": "table", "driver": "sqlite", + }] }) + .to_string(); + assert_eq!(f.run("table-schema", Some(&menu_argument)).unwrap().unwrap(), response); + assert!(!response.contains("private-row-value")); + assert!(schema.get("password").is_none() && schema.get("url").is_none() && schema.get("host").is_none()); + f.plugins.set_capability(ID, "database.schema", false).unwrap(); + let denied = f.run("table-schema", Some(&table)).unwrap_err(); + assert!(denied.message.contains("database.schema")); + assert!(db.is_connected("user-source"), "revoking inspection leaves user connections alone"); + f.plugins.set_capability(ID, "database.schema", true).unwrap(); + f.host.set_project_trust(&f.root, false, false).await.unwrap(); + assert!(f.run("table-schema", Some(&table)).is_err()); + db.disconnect("user-source").await; + assert!(db.connected_table_details("user-source", None, "main", "users").await.is_err()); + assert!(!db.is_connected("user-source"), "schema reads cannot reconnect a disconnected source"); +} diff --git a/crates/ide-plugin/src/runtime.rs b/crates/ide-plugin/src/runtime.rs index f6519e668..245d59949 100644 --- a/crates/ide-plugin/src/runtime.rs +++ b/crates/ide-plugin/src/runtime.rs @@ -64,7 +64,7 @@ use views_bindings::exports::openidea::plugin::view_provider as wit_view; use views_bindings::openidea::plugin::view_types as wit_vt; /// The API version of the world above, `major.minor` of [`host_api`]. -pub const API_VERSION: &str = "1.19"; +pub const API_VERSION: &str = "1.20"; const EPOCH_TICK: Duration = Duration::from_millis(10); pub(crate) const MAX_TEXT: usize = 1 << 20; /// The most text, and the most PNG bytes, `ui.read-clipboard` returns. @@ -87,6 +87,17 @@ pub enum SettingsTarget { } pub trait HostApi: Send + Sync { + /// Read only the schema of a connected project table; database.schema was checked. + fn database_table_schema( + &self, + _root: &Path, + _client: Option<&str>, + _table: &crate::PluginDatabaseTableRef, + _cancel: &CancellationToken, + _timeout: Duration, + ) -> Result { + Err(HostError::Invalid("Database schema access is unavailable on this host".into())) + } /// Creates/replaces this plugin's non-secret project connection settings. fn database_upsert(&self, root: &Path, source: crate::PluginDataSource) -> Result<(), HostError>; /// Removes only an owned data source and its credentials. diff --git a/crates/ide-plugin/src/types.rs b/crates/ide-plugin/src/types.rs index 0a70f2775..0218a2006 100644 --- a/crates/ide-plugin/src/types.rs +++ b/crates/ide-plugin/src/types.rs @@ -1166,3 +1166,47 @@ pub struct RunConfigCompletion { pub replace_start: u32, pub replace_end: u32, } + +/// Identifies a table in an already connected project data source (API 1.20). +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PluginDatabaseTableRef { + pub source_id: String, + pub catalog: Option, + pub schema: String, + pub table: String, +} +/// Read-only column metadata. No row values or connection settings. +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PluginDatabaseColumn { + pub name: String, + pub data_type: String, + pub nullable: bool, + pub default_value: Option, + pub primary_key: bool, + pub comment: Option, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PluginDatabaseIndex { + pub name: String, + pub unique: bool, + pub columns: Vec, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PluginDatabaseForeignKey { + pub columns: Vec, + pub referenced_schema: String, + pub referenced_table: String, + pub referenced_columns: Vec, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PluginDatabaseTableSchema { + pub comment: Option, + pub columns: Vec, + pub indexes: Vec, + pub foreign_keys: Vec, +} diff --git a/crates/ide-plugin/src/wit_host.rs b/crates/ide-plugin/src/wit_host.rs index 10b0fd909..690dfe8ac 100644 --- a/crates/ide-plugin/src/wit_host.rs +++ b/crates/ide-plugin/src/wit_host.rs @@ -3282,6 +3282,60 @@ pub(crate) mod injections_bindings { } impl bindings::openidea::plugin::database::Host for StoreData { + fn describe_table( + &mut self, + project: Resource, + table: bindings::openidea::plugin::database::TableRef, + ) -> Fallible { + if let Err(e) = self.require(Capability::DatabaseSchema) { + return Ok(Err(e)); + } + let root = self.table.get(&project)?.root.clone(); + let table = crate::PluginDatabaseTableRef { + source_id: table.source_id, + catalog: table.catalog, + schema: table.schema, + table: table.table, + }; + let result = + self.host.database_table_schema(&root, self.client(), &table, &self.cancel.token(), self.io_timeout()); + if result.is_err() { + self.grant_io_error_grace(); + } + use bindings::openidea::plugin::database as db; + Ok(result + .map(|s| db::TableSchema { + comment: s.comment, + columns: s + .columns + .into_iter() + .map(|c| db::ColumnSchema { + name: c.name, + data_type: c.data_type, + nullable: c.nullable, + default_value: c.default_value, + primary_key: c.primary_key, + comment: c.comment, + }) + .collect(), + indexes: s + .indexes + .into_iter() + .map(|i| db::IndexSchema { name: i.name, unique: i.unique, columns: i.columns }) + .collect(), + foreign_keys: s + .foreign_keys + .into_iter() + .map(|f| db::ForeignKeySchema { + columns: f.columns, + referenced_schema: f.referenced_schema, + referenced_table: f.referenced_table, + referenced_columns: f.referenced_columns, + }) + .collect(), + }) + .map_err(to_wit)) + } fn upsert_source( &mut self, project: Resource, diff --git a/crates/ide-plugin/tests/api_compat.rs b/crates/ide-plugin/tests/api_compat.rs index 6eda60dca..821ce99b4 100644 --- a/crates/ide-plugin/tests/api_compat.rs +++ b/crates/ide-plugin/tests/api_compat.rs @@ -98,7 +98,7 @@ fn the_sdk_carries_the_hosts_wit() { #[test] fn the_version_check_runs_compatible_components_and_explains_the_rest() { - let host = v("1.19.0"); + let host = v("1.20.0"); for ok in [ "1.0.0", "1.3.0", @@ -118,15 +118,16 @@ fn the_version_check_runs_compatible_components_and_explains_the_rest() { "1.17.0", "1.18.0", "1.19.0", + "1.20.0", "1.0.0-rc.1", ] { assert_eq!(check_api(&v(ok), &host), Ok(()), "{ok}"); } - let newer = check_api(&v("1.20.0"), &host).unwrap_err(); - assert!(newer.contains("1.20") && newer.contains("update OpenIDEA"), "{newer}"); + let newer = check_api(&v("1.21.0"), &host).unwrap_err(); + assert!(newer.contains("1.21") && newer.contains("update OpenIDEA"), "{newer}"); assert!(check_api(&v("2.0.0"), &host).unwrap_err().contains("update OpenIDEA")); let older = check_api(&v("0.2.0"), &host).unwrap_err(); - assert!(older.contains("rebuild it with the 1.19 SDK"), "{older}"); + assert!(older.contains("rebuild it with the 1.20 SDK"), "{older}"); // 0.x: every minor is its own API. assert_eq!(check_api(&v("0.2.0"), &v("0.2.5")), Ok(())); assert!(check_api(&v("0.1.0"), &v("0.2.0")).is_err()); diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm index daae2b84c..1bfe6cae3 100644 Binary files a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources index 8fb7cd5ad..4d7de16cc 100644 --- a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources @@ -1 +1 @@ -8da08e3230812e4f7cf875362c095ac4885c3262636e51b111e95f2fd962e08a +daf3ed46b1e98c6b416c0092a10a02579d2cf97959cedd03df1851a5e76d675d diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm index f4b1dd9fa..18fc6cd44 100644 Binary files a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources index 80763c851..9b478445b 100644 --- a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources @@ -1 +1 @@ -9ebd066471e76d6261ab1b4b1e057a85bfdd9abb9f596149798d573336a6d1af +b54f16ce7e7caf877ea464b50014117fc10f30b761236e5ddcb19ad07254ea13 diff --git a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm index 953fd18c8..21ff58f54 100644 Binary files a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources index 0c8a9054c..996f9469a 100644 --- a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources @@ -1 +1 @@ -cb058e76b7f4d12ea56b157481874f076fd7d549ae15b11cf914e9af56417331 +56e088be4df2db66a03060d388890ff9b68c354e36851ad46665b26bd27ea817 diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm index c658182bc..bcbb4f058 100644 Binary files a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources index 5902d937d..2661e5612 100644 --- a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources @@ -1 +1 @@ -58b531185ceaefbfcd78c62663717d0875aefc20b7f63bcd9cd2f412defbf9a9 +eefdb2d5e0b1fcf96d3ba03e5494513577f43f877d675873d4b922ee71bd3cc5 diff --git a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm index e07ee171c..af8dc374e 100644 Binary files a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources index c54bf1eaf..f6bd9577a 100644 --- a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources @@ -1 +1 @@ -89e515fce0e0cd4029a46c066a2b65592a22178ea77907c520beba447b6bb502 +00c70c0584a32dacdaee29379b805815d17e6d9cb209e1c21d72fbfc18020498 diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm index f82ad8629..1d2d5ce5c 100644 Binary files a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources index 3d19d49c9..dded103ef 100644 --- a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -4e9714318c72fd137fb71234b00f48378256a7558328414aee1911f9eca640bf +e08f776a59706399eca922a324f21835208740a16c2e87911f0c338dd8e25cb2 diff --git a/crates/ide-plugin/tests/fixtures/data-tools/plugin.toml b/crates/ide-plugin/tests/fixtures/data-tools/plugin.toml index 0fda63df1..9d8f0dcf0 100644 --- a/crates/ide-plugin/tests/fixtures/data-tools/plugin.toml +++ b/crates/ide-plugin/tests/fixtures/data-tools/plugin.toml @@ -1,12 +1,12 @@ id = "test.data-tools" name = "Data tools fixture" version = "0.1.0" -engines.openidea = "^1.4" +engines.openidea = "^1.20" wasm = "dist/plugin.wasm" activation = ["on-command:*"] [capabilities] required = ["project.read"] -optional = ["database.sources"] +optional = ["database.sources", "database.schema"] [[contributes.commands]] id = "upsert" @@ -66,3 +66,11 @@ description = "Fixture denied" inputSchema = "arguments.json" readOnly = true destructive = false + +[[contributes.commands]] +id = "table-schema" +title = "Read table schema" + +[[contributes.menus]] +menu = "database.table.context" +command = "table-schema" diff --git a/crates/ide-plugin/tests/fixtures/data-tools/src/lib.rs b/crates/ide-plugin/tests/fixtures/data-tools/src/lib.rs index 98bd09662..cbec2c5ec 100644 --- a/crates/ide-plugin/tests/fixtures/data-tools/src/lib.rs +++ b/crates/ide-plugin/tests/fixtures/data-tools/src/lib.rs @@ -14,6 +14,16 @@ impl Plugin for DataTools { p.upsert_data_source(&source)?; } "remove" => p.remove_data_source(arg.unwrap_or("local"))?, + "table-schema" => { + let value: serde_json::Value = serde_json::from_str(arg.ok_or("table reference required")?) + .map_err(|e| Error::Invalid(e.to_string()))?; + // Accept both the table-menu selection and a direct reference for callers/tests. + let table = + serde_json::from_value(value.get("tables").and_then(|v| v.get(0)).unwrap_or(&value).clone()) + .map_err(|e| Error::Invalid(e.to_string()))?; + let schema = p.database_table_schema(&table)?; + return Ok(Some(serde_json::to_string(&schema).unwrap())); + } "sources" => return Ok(Some(serde_json::to_string(&p.data_sources()?).unwrap())), "credential" => p.set_data_source_credential("local", arg.unwrap_or("secret"))?, "connect" => p.connect_data_source(arg.unwrap_or("local"))?, diff --git a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm index 235e9b525..b236ae14d 100644 Binary files a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources index 179f70c59..0a56573ab 100644 --- a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources @@ -1 +1 @@ -37f6ac9b07a333793798fd909fec9940fdffadd305a0ae1f15d50a918a6e738b +43bc34ad3aafd1d2869cf8f745dbaa0e8fce05ae6e39bf91ab39660cbcfc4740 diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm index 6de9433f3..475247d70 100644 Binary files a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources index a54000828..285b570ff 100644 --- a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources @@ -1 +1 @@ -46b9a5d0dd6670ae30c5c35909c02bc583e6ce4368aaa0df9aaaf917f141ccbe +b4d92a22c5ebadc47284a22be1de2beec6deeffcc2f60c55173b924322588844 diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm index c2c9ff205..1ae0fb833 100644 Binary files a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources index c299da3d4..f74d550bb 100644 --- a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources @@ -1 +1 @@ -c029e8c5d44bd10bfc962747643033ad661406a4e71266060b83b479528ac62f +452aed5f05ac3cc3d299afd74427fd58c5934dec6ca5a239e2a1e347ba036044 diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm index 85f6f8ca0..abb638a52 100644 Binary files a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources index eac8eeffb..1888ee1c2 100644 --- a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources @@ -1 +1 @@ -df74de6fd1067530b30e32dc9955d2540cc11a84ab366c1d55286b1f666171d3 +2abcea42de506e9e28a0970ba2a8615c7cc88d769cb5fa47fe3bb57e03af5258 diff --git a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm index be3e4bbb0..0b7912bf9 100644 Binary files a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources index e80136b9b..48832a9e2 100644 --- a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources @@ -1 +1 @@ -010115b90cf7c62b304a419a85d2bf1e87a08cf8b71a22b83db7228c74fc879c +60e1a1925b3d83ea34be69727b9e8804ba3a1db767b7a06f87bcad6ab326a604 diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm index cecf57dcf..758a85a94 100644 Binary files a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources index 2bbda3160..bc06e075b 100644 --- a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources @@ -1 +1 @@ -4d64d801f5b861964a90907eb2d35fcfaac0fd5bba32f6fa739d419370ad34bb +92d626a131d5b8b82781a3cb7d87a293ddb0e5e81450bef17dc505c12f2a4f57 diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm index 7beffd487..80f43dd49 100644 Binary files a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources index 7023b8750..c6dc59815 100644 --- a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources @@ -1 +1 @@ -91dbf215e6388c1c4c8f09a8194d66888b0060bb44ee590b63a25aa3f8b1cdf8 +86ec4a4ebc1d770b0e6973d9169544111fce24485f3eed8b7040d7dce8280dcd diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm index 3fad98b9e..74d834303 100644 Binary files a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources index 961be691a..14b3627f7 100644 --- a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources @@ -1 +1 @@ -b83536a1c2620edaddc9712ebfcc284d83fd59054f17b4e10c99f3d55fe0a8bf +254dddbf9c67f00451fc173602532e2e4fe92a6fd8d3d91824c950a403c7583c diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm index 7bd265f1a..c66d4aa57 100644 Binary files a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources index bc090fd53..320d9d903 100644 --- a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources @@ -1 +1 @@ -2af8aa827092f59d6faa02d4084f79a66bda9ef5211a1450542361702d04e7ae +49e66ff2b91e070477c272ac1c5c60367148b274d75bb7d92efca0b1d5092f6a diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm index c670f4053..fc20057cb 100644 Binary files a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources index 40a1e6f09..a8bd9832c 100644 --- a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources @@ -1 +1 @@ -93c276cf31b807543d700c2010a128741b269d897993882ff378061b1ed0b56d +cfb61fe65b344d86bf71a821c1216963d9ab7789206a292450b1d66222d6cbc5 diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm index 9e0e0064e..677e13359 100644 Binary files a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources index 28a85a3c6..23f771220 100644 --- a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources @@ -1 +1 @@ -ed76d43bce1e0801aac9010ccbb6d6e5cb680283df6467961156d3ae7a6c3177 +706e69379855967f598abbcc3bcc955cb5581ca4b009d5220f4785ccb05dda0f diff --git a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm index 566d3e186..016cdafe0 100644 Binary files a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources index 2de291c7d..217e1d6e2 100644 --- a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources @@ -1 +1 @@ -c2c601d62f588a9618844e46e62998e26389a4eaaba1f3be90d0c70c6c19050a +118c6f4870e99d57acfc9fbb265031a3a7d1dfc03b4408be8c8b5eade33e4f38 diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm index 90941779d..92def6f8e 100644 Binary files a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources index f51da0a70..ee87125cd 100644 --- a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources @@ -1 +1 @@ -10eeb474973e8dea250698a0322ce19705ec86beef29730500ebe611d3f796fa +19b04c02c5230c0700bdc8fe8a3cae266422aa23e8d7e932b7dafd546e41846d diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm index 3ec2c5805..d3b36052c 100644 Binary files a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources index 052d134cf..9350ea10c 100644 --- a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources @@ -1 +1 @@ -3d65392e8a6723b33061b243deace1e6ede4d6d258c4c16719ed7533a2b1e3b1 +14e46bbf68efaacaff75627814be666dcf00460656ba7e66b7fb088317ce6c79 diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm index 73dda3303..0a44231d6 100644 Binary files a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources index 655dc4049..c070bcab7 100644 --- a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources @@ -1 +1 @@ -33396b01be200316e5922b6db22e0bd498aad4c77a52254b24134c31c1f7a256 +55afdbdb4db919c59a38b14eb6483c911934d64d433ef19106098bfde4830a91 diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm index fa5d367b7..1dafc3398 100644 Binary files a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources index d59c05d9a..ae825c496 100644 --- a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources @@ -1 +1 @@ -7a98500c653f18188570c91cadc4fc3c7e2bed2fcdd2ba8945a98bc13b7c5af4 +99099a7f01295188bade661777d926fd12ba434ec4ff36035ee1b13523d63ae8 diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm index 978ace241..41472ecd5 100644 Binary files a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources index 08b00a4dd..c8de6f86f 100644 --- a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources @@ -1 +1 @@ -7ac9e871f691e989cdef0d4ac3baf8fa338114ad906befd229a124e50897898d +ff6ecc3baa94d7cd4447f3d9f2a3f819ee44dac3564fdfba3a5f88a0637c0af0 diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm index dd6045ef2..a51fba83e 100644 Binary files a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources index 4f7882862..505503fff 100644 --- a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources @@ -1 +1 @@ -e6bfa4a44f635fafd16103235424e40b8cd6849ed83f582af84fc9baac800882 +45990bb70318e04cb69c8ffa5c980b85e65bd860559b10507061762f8ecb38b3 diff --git a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm index 97deb9eb4..faad1a731 100644 Binary files a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources index b1fdec97e..69dfcd17d 100644 --- a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources @@ -1 +1 @@ -7eccc42692e9d289e15fe131195ed67ebe9102f387cef02da19a581f37d729dc +cb21ced740ff159017a96075e41b31782c062db10596e4286327fb4d002b6ebf diff --git a/crates/ide-plugin/tests/fixtures/misbehave/src/lib.rs b/crates/ide-plugin/tests/fixtures/misbehave/src/lib.rs index 5edc8c629..e00f52fc2 100644 --- a/crates/ide-plugin/tests/fixtures/misbehave/src/lib.rs +++ b/crates/ide-plugin/tests/fixtures/misbehave/src/lib.rs @@ -5,9 +5,9 @@ wit_bindgen::generate!({ inline: " package fixture:misbehave; world misbehave { - include openidea:plugin/plugin-syntax@1.19.0; - export openidea:plugin/providers@1.19.0; - export openidea:plugin/file-actions@1.19.0; + include openidea:plugin/plugin-syntax@1.20.0; + export openidea:plugin/providers@1.20.0; + export openidea:plugin/file-actions@1.20.0; } ", path: "../../../../../wit", diff --git a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm index 2461adf0c..1e2d6e6cb 100644 Binary files a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources index 8c5bb7eff..1fa64d784 100644 --- a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources @@ -1 +1 @@ -a09c1f93e121b27d71bb6ac717a1222e240799f2bc0a6def8805ab4a62bed1a6 +9bdc92f81b7985bec88bd2b3929771df22f1d31945e575a3a71ca705aad4d1dc diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm index 7a216ff72..cda86bde4 100644 Binary files a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources index a5adb83d1..b8541d8b7 100644 --- a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources @@ -1 +1 @@ -8d34f0080002a1a68df23ba8fefb5cec34a986ca4610866f99007c6c62792ff5 +3cbfd56bef0062d1fb25854efe256c34c7de23ddf1ae4611e05119410a487f4b diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm index 291007136..60ac434ec 100644 Binary files a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources index 063aa3930..f3e7c787e 100644 --- a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources @@ -1 +1 @@ -f1f0d0d2d8c45fe4ce0c948a129c68e433f2d4ae068deb8bd7cbceb0ea015f27 +87c9742d4700629243bbfd544d227c64bbb478a0607bd21b1a16072eb50b6b8e diff --git a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm index b31872bd8..db3700ff7 100644 Binary files a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources index 2892ae4e9..434b616c6 100644 --- a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources @@ -1 +1 @@ -8d107d10fbb8916cce95a4e2291830449f2dc9d6341e3dbba51a5ae7642d17d5 +8bdf895f76e7615b03cd8d2e50ee8272e9598a6f21426a4ec86e124fbaf86741 diff --git a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm index 5d8aa83bf..70985baf3 100644 Binary files a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources index 71e26edcc..69c72a008 100644 --- a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources @@ -1 +1 @@ -966ae3021ee93af461d19c78053d42918917e7a754dac5becda21fba3e8b9ddd +63cc4ad099d6c383b78e46dddc5b578c899cfc42e4b9dc5726704f1d6c8da83a diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm index f8f00e9b9..9c9f84703 100644 Binary files a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources index c3c313412..30936e80d 100644 --- a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources @@ -1 +1 @@ -161ef690cbb2b0c4aadcc0719f9dbe58a5ee0235895427f8137816d270d0ba6a +213bdb00682f6e573f54ad07698e5090f9bc1ccd3ebfc9cf7f703b2fdce9f30a diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm index 29869297b..d83d709a5 100644 Binary files a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources index 2cfc8ebc8..ea1bf4e4f 100644 --- a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources @@ -1 +1 @@ -3f1cdd40349346eab3ba5f175d674a202fc6237b5c83388767e3667bea51515f +1facc9f2d4e26f87e8a80719b560b61d7e6a3c953753cfe20bc2eba9b31934d1 diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm index 49839e7f9..67efd80a3 100644 Binary files a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources index 1fd267a4b..932b06cb5 100644 --- a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources @@ -1 +1 @@ -429ffc70da72af8532d68ebb741fb4a694465b5460567c42ceeb76f66ca02165 +7fbe4b0ac9d49efd8300867d9b447bced49a7f3d9ab7bcebd74b11c7c8ff546f diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm index 3de901560..0fcf5aa9a 100644 Binary files a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources index f3055ff33..2adbaeb77 100644 --- a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources @@ -1 +1 @@ -e7141ca998b249cbc0a4dc0565fa621119f25c9a213ccfdbd6d3b62378c47239 +2c4cc949885b3d1d0f4a9dbc44c239d55ed4e43f71c8b09a8da3e9f31a439841 diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm index 426d181c7..e1ae870eb 100644 Binary files a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources index 4d9153370..4ca0325e2 100644 --- a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources @@ -1 +1 @@ -5cae8da91f43fa48fa84b0a7c71530f0629cdac20bbbda4cd0d1f405e9d3fb72 +23c9187f4deb89351de32a52e8f08b4933d2bbe72fcf3c9a7c9b29ae20bbdb44 diff --git a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm index 909b88f7d..1702ecdf8 100644 Binary files a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources index 8a921794b..97ca43e3a 100644 --- a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources @@ -1 +1 @@ -b1f943eb3661ec38eed856269d30009738ec833a75e7a7a0da09358afa6dff36 +e7159f2069bbfbdb68b8770040772949013b733e16513d57333664d6a945a326 diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm index 92f14f724..09d1a4b55 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources index c9484bf08..14395bcbb 100644 --- a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources @@ -1 +1 @@ -5f525aeb82bde5016791285b92674347b303edd27770d67028f32dd8071e4ee1 +29f64f3236c46cd1b0e7915736fdb41f3826161c4d950aac7ed7b6b0767786be diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm index b5faf3139..a805d17bb 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources index 2413b107d..4ad9d777f 100644 --- a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources @@ -1 +1 @@ -a803720da55b706875485399f700cc6d8d6b7e9adca74dc9931052b4143b4e27 +072c75538a1e36064fafd69f66e7d40024b4f5909f3d6acf8191071dbe195c92 diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm index b472fb63e..98c4b950f 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources index 6de9e8f15..35ea2bc0e 100644 --- a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources @@ -1 +1 @@ -8dd5fd56707cf120f1bcddec5093c5d5a075faae8dcb4ad17b6797efdcee9621 +ecc4f6f73209bd2d4d10353ed73a3a8629381cf6c8901673ae8ce19541136b96 diff --git a/docs/en/plugins/capabilities.mdx b/docs/en/plugins/capabilities.mdx index 9dc1983b6..8fa3802e7 100644 --- a/docs/en/plugins/capabilities.mdx +++ b/docs/en/plugins/capabilities.mdx @@ -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:` | 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:` | High | `host::fs` reads outside the projects, under that path | 1.0 (the `fs` interface: 1.3) | | `fs.write:` | High | `host::fs` writes outside the projects, under that path; does not imply reading | 1.3 | | `process:` | High | Run that program: `run_process`, `run_command`, `start`, terminals, language servers, debug adapters, runs | 1.0 | diff --git a/docs/en/plugins/guides/database.mdx b/docs/en/plugins/guides/database.mdx index 4de5a55ba..159736c20 100644 --- a/docs/en/plugins/guides/database.mdx +++ b/docs/en/plugins/guides/database.mdx @@ -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 = 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. diff --git a/docs/en/plugins/versioning.mdx b/docs/en/plugins/versioning.mdx index 7d85fca96..6c399d5a6 100644 --- a/docs/en/plugins/versioning.mdx +++ b/docs/en/plugins/versioning.mdx @@ -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. 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 '' with " 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). diff --git a/docs/zh/plugins/capabilities.mdx b/docs/zh/plugins/capabilities.mdx index b82cf4a1f..048333ee0 100644 --- a/docs/zh/plugins/capabilities.mdx +++ b/docs/zh/plugins/capabilities.mdx @@ -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 | diff --git a/docs/zh/plugins/guides/database.mdx b/docs/zh/plugins/guides/database.mdx index 903ea8f4d..bf550ec51 100644 --- a/docs/zh/plugins/guides/database.mdx +++ b/docs/zh/plugins/guides/database.mdx @@ -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 项。远程项目使用项目现有的数据库子系统。 diff --git a/docs/zh/plugins/versioning.mdx b/docs/zh/plugins/versioning.mdx index 9bc71b984..54b26c257 100644 --- a/docs/zh/plugins/versioning.mdx +++ b/docs/zh/plugins/versioning.mdx @@ -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)。 diff --git a/e2e/databasePluginMenu.spec.ts b/e2e/databasePluginMenu.spec.ts new file mode 100644 index 000000000..d653ad33a --- /dev/null +++ b/e2e/databasePluginMenu.spec.ts @@ -0,0 +1,80 @@ +import { expect, stubDesktop, test } from "./fixtures"; + +test("table menu contributions preserve selected table identities", async ({ workbench: page }, info) => { + await stubDesktop(page); + await page.evaluate(async () => { + const storePath = "/src/features/database/store.ts"; + const contributionsPath = "/src/workbench/contributions.ts"; + const { useDatabase } = await import(storePath); + const { toolWindowService } = await import(contributionsPath); + useDatabase.setState({ + sources: [{ id: "local", name: "Inventory", driver: "sqlite", file: "inventory.sqlite" }], + loaded: true, + connected: new Set(["local"]), + schemas: { local: { status: "ok", value: ["main"] } }, + foldersLoaded: true, + tables: { + ["local\u0000main"]: { + status: "ok", + value: [ + { name: "users", kind: "table" }, + { name: "orders", kind: "table" }, + ], + }, + }, + }); + toolWindowService().show("database", true); + }); + const panel = page.locator('section[aria-label="Database"]'); + const source = panel.getByRole("treeitem").filter({ hasText: "Inventory" }); + await source.locator("[data-tree-toggle]").click(); + const schema = panel.getByRole("treeitem").filter({ hasText: /^main/ }); + if (await schema.count()) await schema.locator("[data-tree-toggle]").click(); + await panel + .getByRole("treeitem") + .filter({ hasText: /^tables/ }) + .locator("[data-tree-toggle]") + .click(); + const users = panel.getByRole("treeitem").filter({ hasText: /^users/ }); + await expect(users).toBeVisible(); + await users.click({ button: "right" }); + await expect(page.getByRole("menu").last()).toBeVisible(); + await page.screenshot({ path: info.outputPath("before.png"), animations: "disabled" }); + await page.keyboard.press("Escape"); + await page.evaluate(async () => { + const actionsPath = "/src/platform/actions.ts"; + const projectionPath = "/src/features/plugins/projection.ts"; + const { registerAction } = await import(actionsPath); + const { syncUiContributions } = await import(projectionPath); + registerAction({ + id: "plugin.mapper.generate", + title: "Generate MyBatis mapper", + run: ({ arg }: { arg?: unknown }) => { + Object.assign(window, { __tableSelection: arg }); + }, + }); + syncUiContributions( + [ + { + pluginId: "mapper", + point: "menus", + key: "database.table.context/generate", + decl: { menu: "database.table.context", command: "generate", when: "databaseObjectKind == table" }, + }, + ], + [{ id: "mapper", name: "Mapper generator", enabled: true, status: "active", icon: null }], + ); + }); + await users.click({ button: "right" }); + const generate = page.getByRole("menuitem", { name: "Generate MyBatis mapper" }); + await expect(generate).toBeVisible(); + await page.screenshot({ path: info.outputPath("after.png"), animations: "disabled" }); + await generate.click(); + await expect + .poll(() => page.evaluate(() => (window as unknown as { __tableSelection?: string }).__tableSelection)) + .toBeTruthy(); + const selection = await page.evaluate(() => (window as unknown as { __tableSelection: string }).__tableSelection); + expect(JSON.parse(selection)).toEqual({ + tables: [{ sourceId: "local", catalog: null, schema: "main", table: "users", kind: "table", driver: "sqlite" }], + }); +}); diff --git a/plugins/README.md b/plugins/README.md index 20eafc45a..2cfe575df 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -1293,6 +1293,25 @@ its purpose) and a trusted project. Without the grant the call returns `error::d An unknown session, a malformed id, a session another task already holds, or a `cwd` that does not match the recording is an invalid or not-found error, not a fork. +### Database table menus and schema inspection (API 1.20) + +With `engines.openidea = "^1.20"`, contribute a command to +`database.table.context` to receive a JSON string `{ "tables": [...] }`. +Each selected table has `sourceId`, nullable `catalog`, `schema`, `table`, `kind` +and `driver`; no connection settings or credentials are passed. Conditions can +use `databaseDriver`, `databaseObjectKind`, `databaseSchema`, `databaseTable` +and `databaseSelectionCount`; each selected table must match. + +Declare the separate medium-risk `database.schema` capability and call +`Project::database_table_schema(&DatabaseTableRef)` (`database.describe-table`). +It reads columns, indexes, foreign keys and comments from an already connected +source in a trusted project, including user-created sources. It returns no row +data or credentials and cannot execute SQL or connect sources. Source ownership +management continues to require `database.sources` independently. Requests are +cancellable, bounded by the I/O timeout and limited to 4096 entries per collection. +See the [database guide](../docs/en/plugins/guides/database.mdx) for a complete manifest +and Rust example; generating files additionally requires `project.write`. + ### Database sources (API 1.4) Declare `database.sources` (medium risk). All five calls require it and a diff --git a/plugins/official/ai-completion/dist/plugin.wasm b/plugins/official/ai-completion/dist/plugin.wasm index b3ac50a4b..b76d6edfc 100644 Binary files a/plugins/official/ai-completion/dist/plugin.wasm and b/plugins/official/ai-completion/dist/plugin.wasm differ diff --git a/plugins/official/ai-completion/dist/plugin.wasm.sources b/plugins/official/ai-completion/dist/plugin.wasm.sources index e1a97d1b7..253a5cf12 100644 --- a/plugins/official/ai-completion/dist/plugin.wasm.sources +++ b/plugins/official/ai-completion/dist/plugin.wasm.sources @@ -1 +1 @@ -385b624ee9593d759a2ce22d4427edc0f06954d0e98f458a77d780e5a3dbe92a +4b1f2303c8b795c11e9c6c57d980005e28b0bdf53a98999175db0d573b38554f diff --git a/plugins/official/blame-annotations/dist/plugin.wasm b/plugins/official/blame-annotations/dist/plugin.wasm index 065eeae76..41b96b13d 100644 Binary files a/plugins/official/blame-annotations/dist/plugin.wasm and b/plugins/official/blame-annotations/dist/plugin.wasm differ diff --git a/plugins/official/blame-annotations/dist/plugin.wasm.sources b/plugins/official/blame-annotations/dist/plugin.wasm.sources index 7e64476b9..accba9079 100644 --- a/plugins/official/blame-annotations/dist/plugin.wasm.sources +++ b/plugins/official/blame-annotations/dist/plugin.wasm.sources @@ -1 +1 @@ -1949060673bb04cc457f22af3a3013185da7fe29af593ca3896b6ce1e519819f +3cabfcb916565d4ba98e10c1d935ecd8771e03eade5586a03a387e728d14ae68 diff --git a/plugins/official/checkstyle/dist/plugin.wasm b/plugins/official/checkstyle/dist/plugin.wasm index 1f14556ac..d791651db 100644 Binary files a/plugins/official/checkstyle/dist/plugin.wasm and b/plugins/official/checkstyle/dist/plugin.wasm differ diff --git a/plugins/official/checkstyle/dist/plugin.wasm.sources b/plugins/official/checkstyle/dist/plugin.wasm.sources index f2f81fd0e..589564876 100644 --- a/plugins/official/checkstyle/dist/plugin.wasm.sources +++ b/plugins/official/checkstyle/dist/plugin.wasm.sources @@ -1 +1 @@ -a1db2b630b6b91b4bad39d7e06f0808a7d50167a49dcc35adc9c77c031df541c +c3dc2b4a769b65efc2958bcceed0249e3fa999f2592441fdf92338d7be61397a diff --git a/plugins/official/container-runner/dist/plugin.wasm b/plugins/official/container-runner/dist/plugin.wasm index e051e345a..f5dcb79e0 100644 Binary files a/plugins/official/container-runner/dist/plugin.wasm and b/plugins/official/container-runner/dist/plugin.wasm differ diff --git a/plugins/official/container-runner/dist/plugin.wasm.sources b/plugins/official/container-runner/dist/plugin.wasm.sources index a21530ca6..d10e2e054 100644 --- a/plugins/official/container-runner/dist/plugin.wasm.sources +++ b/plugins/official/container-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -cc6bc4b394758a6f7417d44b2ce1cd6444af26533e233850f92027b15a930a0e +22d0cf6590e46fb79d2bd92ab9ef1939d5d7babb0ff7d8d236b62878b6443ade diff --git a/plugins/official/csv-editor/dist/plugin.wasm b/plugins/official/csv-editor/dist/plugin.wasm index 200e566e0..b5f02081e 100644 Binary files a/plugins/official/csv-editor/dist/plugin.wasm and b/plugins/official/csv-editor/dist/plugin.wasm differ diff --git a/plugins/official/csv-editor/dist/plugin.wasm.sources b/plugins/official/csv-editor/dist/plugin.wasm.sources index 05ab225c2..3e2b39fba 100644 --- a/plugins/official/csv-editor/dist/plugin.wasm.sources +++ b/plugins/official/csv-editor/dist/plugin.wasm.sources @@ -1 +1 @@ -d84518ae53618a8762ba01f2ce1cd5d1edfbb020280543fa0fa4f5d86806fa78 +1e9d095de03a7c60a820a88407b384188b55f79d2a231b613e9b8b03c20387b1 diff --git a/plugins/official/git-toolbox/dist/plugin.wasm b/plugins/official/git-toolbox/dist/plugin.wasm index 6966a5ee6..e6e4cff35 100644 Binary files a/plugins/official/git-toolbox/dist/plugin.wasm and b/plugins/official/git-toolbox/dist/plugin.wasm differ diff --git a/plugins/official/git-toolbox/dist/plugin.wasm.sources b/plugins/official/git-toolbox/dist/plugin.wasm.sources index 3b9e57ee5..c43dd5721 100644 --- a/plugins/official/git-toolbox/dist/plugin.wasm.sources +++ b/plugins/official/git-toolbox/dist/plugin.wasm.sources @@ -1 +1 @@ -3c3c05b19ed460c28710e4818b30767904853063179c826fc8ffb0bae5247e5a +013d920f8aaad0ebb44d1a11ef50d27aaedd0614241ce7be4f50eac9e996f986 diff --git a/plugins/official/graphviz/dist/plugin.wasm b/plugins/official/graphviz/dist/plugin.wasm index be516923a..c5c74e310 100644 Binary files a/plugins/official/graphviz/dist/plugin.wasm and b/plugins/official/graphviz/dist/plugin.wasm differ diff --git a/plugins/official/graphviz/dist/plugin.wasm.sources b/plugins/official/graphviz/dist/plugin.wasm.sources index 18449ace6..86ea98e43 100644 --- a/plugins/official/graphviz/dist/plugin.wasm.sources +++ b/plugins/official/graphviz/dist/plugin.wasm.sources @@ -1 +1 @@ -dcbfe5bc29ec9eb87e5ce3d04dd8318ce1a0f072aabbba85e8a1946b9ecac897 +f6f54d8c8416bf5d2ab7da51614c044ba3252964ab913c49dfb09c9e6604f750 diff --git a/plugins/official/key-promoter/dist/plugin.wasm b/plugins/official/key-promoter/dist/plugin.wasm index 00be8034d..6dd6481cc 100644 Binary files a/plugins/official/key-promoter/dist/plugin.wasm and b/plugins/official/key-promoter/dist/plugin.wasm differ diff --git a/plugins/official/key-promoter/dist/plugin.wasm.sources b/plugins/official/key-promoter/dist/plugin.wasm.sources index 5766f6c57..45055cf8c 100644 --- a/plugins/official/key-promoter/dist/plugin.wasm.sources +++ b/plugins/official/key-promoter/dist/plugin.wasm.sources @@ -1 +1 @@ -b9244a4dbf041102e2edede46844aff49ffe34df572bc69a9ebd68a8c96aa036 +c64b316772ea26ce5e2669025d55ba4af9b9a22f225971f361ee9716ae1cbbd4 diff --git a/plugins/official/license-header/dist/plugin.wasm b/plugins/official/license-header/dist/plugin.wasm index d70da890d..c7906b376 100644 Binary files a/plugins/official/license-header/dist/plugin.wasm and b/plugins/official/license-header/dist/plugin.wasm differ diff --git a/plugins/official/license-header/dist/plugin.wasm.sources b/plugins/official/license-header/dist/plugin.wasm.sources index fde693858..023242b9d 100644 --- a/plugins/official/license-header/dist/plugin.wasm.sources +++ b/plugins/official/license-header/dist/plugin.wasm.sources @@ -1 +1 @@ -b76b6599aeb9c7f0b6e7d58b413b7c013a049879af7605ad44de5749fc4734f0 +1c40bd1a24c77eade5f617d99b8719e1961979c30a77c613e07d97c1abc5b03f diff --git a/plugins/official/mybatis/dist/plugin.wasm b/plugins/official/mybatis/dist/plugin.wasm index 460ce48b0..d0670aac6 100644 Binary files a/plugins/official/mybatis/dist/plugin.wasm and b/plugins/official/mybatis/dist/plugin.wasm differ diff --git a/plugins/official/mybatis/dist/plugin.wasm.sources b/plugins/official/mybatis/dist/plugin.wasm.sources index b13e6a5aa..97fe15152 100644 --- a/plugins/official/mybatis/dist/plugin.wasm.sources +++ b/plugins/official/mybatis/dist/plugin.wasm.sources @@ -1 +1 @@ -7c4141ad8946f38daec7bc687066a51c63323613382512346eeb8ff1c91ca759 +bcf00a07cfc9a894d3effd88a3dbc4d000ac2abc057358db1afe17f9fde93710 diff --git a/plugins/official/regex-tester/dist/plugin.wasm b/plugins/official/regex-tester/dist/plugin.wasm index 2396f9a1f..301868d7f 100644 Binary files a/plugins/official/regex-tester/dist/plugin.wasm and b/plugins/official/regex-tester/dist/plugin.wasm differ diff --git a/plugins/official/regex-tester/dist/plugin.wasm.sources b/plugins/official/regex-tester/dist/plugin.wasm.sources index 063a194d9..c6132e841 100644 --- a/plugins/official/regex-tester/dist/plugin.wasm.sources +++ b/plugins/official/regex-tester/dist/plugin.wasm.sources @@ -1 +1 @@ -d20b93d3e426f9b1ec99e7d1f284c3c7b22bf2cb367ae30fb4915c18d025697a +811e77cd9740eecd4007f1104343b6d0943920160a5ab7c41018c932ab5148f6 diff --git a/plugins/official/solidity/dist/plugin.wasm b/plugins/official/solidity/dist/plugin.wasm index 1fd75ae51..7fceec022 100644 Binary files a/plugins/official/solidity/dist/plugin.wasm and b/plugins/official/solidity/dist/plugin.wasm differ diff --git a/plugins/official/solidity/dist/plugin.wasm.sources b/plugins/official/solidity/dist/plugin.wasm.sources index 01c979517..1bb0af822 100644 --- a/plugins/official/solidity/dist/plugin.wasm.sources +++ b/plugins/official/solidity/dist/plugin.wasm.sources @@ -1 +1 @@ -001fb007580783881f2c7fe08121796d930db6fc0aeb82a6fbb077028355f5dc +cef63193655a8fe67397b6cc7c60a082cd0feddea6a7516d8a77c5feb15d5588 diff --git a/plugins/official/string-tools/dist/plugin.wasm b/plugins/official/string-tools/dist/plugin.wasm index 47759c1a6..172db556b 100644 Binary files a/plugins/official/string-tools/dist/plugin.wasm and b/plugins/official/string-tools/dist/plugin.wasm differ diff --git a/plugins/official/string-tools/dist/plugin.wasm.sources b/plugins/official/string-tools/dist/plugin.wasm.sources index 82a54f73d..ac6181028 100644 --- a/plugins/official/string-tools/dist/plugin.wasm.sources +++ b/plugins/official/string-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -9c6070c56d9aef747cb91ffa336727273ae3e6124dabf939a08e18123acc2ea7 +845c85070a383baa9b28c451175273db83a0f11c14a089cd4ec39eeb302f9e7c diff --git a/plugins/official/test-runner/dist/plugin.wasm b/plugins/official/test-runner/dist/plugin.wasm index ba9ff17bb..73599dec1 100644 Binary files a/plugins/official/test-runner/dist/plugin.wasm and b/plugins/official/test-runner/dist/plugin.wasm differ diff --git a/plugins/official/test-runner/dist/plugin.wasm.sources b/plugins/official/test-runner/dist/plugin.wasm.sources index 0186a6d84..e176486e4 100644 --- a/plugins/official/test-runner/dist/plugin.wasm.sources +++ b/plugins/official/test-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -923fa9c58a1d934b8053aeaed6672fbe294c2ebfa69434f8f42758ff4f60624e +48f302f820ec837bace09a3299d8d3835314445c7da0c12f2f2c49559655832f diff --git a/plugins/official/todo-finder/dist/plugin.wasm b/plugins/official/todo-finder/dist/plugin.wasm index d80ba4d62..b51b3b4c4 100644 Binary files a/plugins/official/todo-finder/dist/plugin.wasm and b/plugins/official/todo-finder/dist/plugin.wasm differ diff --git a/plugins/official/todo-finder/dist/plugin.wasm.sources b/plugins/official/todo-finder/dist/plugin.wasm.sources index 0a5c3d32d..003bb4992 100644 --- a/plugins/official/todo-finder/dist/plugin.wasm.sources +++ b/plugins/official/todo-finder/dist/plugin.wasm.sources @@ -1 +1 @@ -847ea10dc57fc7062eb680c768d284502c33a78a1ce2783ed6d9fe27078f1c46 +f59fcefbb81a5df556fb806ffc824460f24d0935c2a60e72889ed0124ae62a3c diff --git a/sdk/rust/openidea-plugin/src/host.rs b/sdk/rust/openidea-plugin/src/host.rs index e2000567e..1d07622d9 100644 --- a/sdk/rust/openidea-plugin/src/host.rs +++ b/sdk/rust/openidea-plugin/src/host.rs @@ -935,6 +935,49 @@ mod imp { } } + pub fn database_table_schema(project: &ProjectRes, table: &DatabaseTableRef) -> Result<DatabaseTableSchema, Error> { + use wit::database as db; + let s = wit::database::describe_table( + project, + &db::TableRef { + source_id: table.source_id.clone(), + catalog: table.catalog.clone(), + schema: table.schema.clone(), + table: table.table.clone(), + }, + ) + .map_err(error)?; + Ok(DatabaseTableSchema { + comment: s.comment, + columns: s + .columns + .into_iter() + .map(|c| DatabaseColumn { + name: c.name, + data_type: c.data_type, + nullable: c.nullable, + default_value: c.default_value, + primary_key: c.primary_key, + comment: c.comment, + }) + .collect(), + indexes: s + .indexes + .into_iter() + .map(|i| DatabaseIndex { name: i.name, unique: i.unique, columns: i.columns }) + .collect(), + foreign_keys: s + .foreign_keys + .into_iter() + .map(|f| DatabaseForeignKey { + columns: f.columns, + referenced_schema: f.referenced_schema, + referenced_table: f.referenced_table, + referenced_columns: f.referenced_columns, + }) + .collect(), + }) + } pub fn database_upsert(project: &ProjectRes, source: &PluginDataSource) -> Result<(), Error> { wit::database::upsert_source( project, @@ -1287,6 +1330,11 @@ impl Project { pub fn remove_data_source(&self, id: &str) -> Result<(), Error> { imp::database_remove(&self.inner, id) } + /// Read the schema of an already connected project table, including user sources (API 1.20). + /// Requires database.schema and project trust; never returns rows or credentials. + pub fn database_table_schema(&self, table: &DatabaseTableRef) -> Result<DatabaseTableSchema, Error> { + imp::database_table_schema(&self.inner, table) + } /// Lists only this plugin's private source ids. pub fn data_sources(&self) -> Result<Vec<String>, Error> { imp::database_sources(&self.inner) diff --git a/sdk/rust/openidea-plugin/src/lib.rs b/sdk/rust/openidea-plugin/src/lib.rs index 609f138c1..dcfaa11ca 100644 --- a/sdk/rust/openidea-plugin/src/lib.rs +++ b/sdk/rust/openidea-plugin/src/lib.rs @@ -115,7 +115,7 @@ pub mod completion_list_bindings { export_macro_name: "__export_completion_list_world", default_bindings_module: "openidea_plugin::completion_list_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, }, }); } @@ -132,7 +132,7 @@ pub mod providers_bindings { export_macro_name: "__export_editor_providers_world", default_bindings_module: "openidea_plugin::providers_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, }, }); } @@ -149,10 +149,10 @@ pub mod views_bindings { export_macro_name: "__export_views_world", default_bindings_module: "openidea_plugin::views_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/workspace@1.19.0": crate::bindings::openidea::plugin::workspace, - "openidea:plugin/editor@1.19.0": crate::bindings::openidea::plugin::editor, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/workspace@1.20.0": crate::bindings::openidea::plugin::workspace, + "openidea:plugin/editor@1.20.0": crate::bindings::openidea::plugin::editor, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, }, }); } @@ -164,7 +164,7 @@ pub mod indexing_bindings { world: "indexing", path: "wit", pub_export_macro: true, export_macro_name: "__export_indexing_world", default_bindings_module: "openidea_plugin::indexing_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -176,10 +176,10 @@ pub mod details_bindings { export_macro_name: "__export_details_world", default_bindings_module: "openidea_plugin::details_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/workspace@1.19.0": crate::bindings::openidea::plugin::workspace, - "openidea:plugin/editor@1.19.0": crate::bindings::openidea::plugin::editor, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/workspace@1.20.0": crate::bindings::openidea::plugin::workspace, + "openidea:plugin/editor@1.20.0": crate::bindings::openidea::plugin::editor, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, }, }); } @@ -191,7 +191,7 @@ pub mod semantic_bindings { world: "semantic-tokens", path: "wit", pub_export_macro: true, export_macro_name: "__export_semantic_tokens_world", default_bindings_module: "openidea_plugin::semantic_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -203,8 +203,8 @@ pub mod diagnostics_bindings { export_macro_name: "__export_diagnostics_world", default_bindings_module: "openidea_plugin::diagnostics_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/diagnostics@1.19.0": crate::bindings::openidea::plugin::diagnostics, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/diagnostics@1.20.0": crate::bindings::openidea::plugin::diagnostics, }, }); } @@ -216,7 +216,7 @@ pub mod hover_bindings { world: "hover", path: "wit", pub_export_macro: true, export_macro_name: "__export_hover_world", default_bindings_module: "openidea_plugin::hover_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -228,11 +228,11 @@ pub mod commit_checks_bindings { export_macro_name: "__export_commit_checks_world", default_bindings_module: "openidea_plugin::commit_checks_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/workspace@1.19.0": crate::bindings::openidea::plugin::workspace, - "openidea:plugin/editor@1.19.0": crate::bindings::openidea::plugin::editor, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, - "openidea:plugin/commit@1.19.0": crate::bindings::openidea::plugin::commit, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/workspace@1.20.0": crate::bindings::openidea::plugin::workspace, + "openidea:plugin/editor@1.20.0": crate::bindings::openidea::plugin::editor, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/commit@1.20.0": crate::bindings::openidea::plugin::commit, }, }); } @@ -244,7 +244,7 @@ pub mod inlay_bindings { world: "inlay-hints", path: "wit", pub_export_macro: true, export_macro_name: "__export_inlay_hints_world", default_bindings_module: "openidea_plugin::inlay_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -255,7 +255,7 @@ pub mod file_actions_bindings { world: "file-actions-provider", path: "wit", pub_export_macro: true, export_macro_name: "__export_file_actions_world", default_bindings_module: "openidea_plugin::file_actions_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -267,10 +267,10 @@ pub mod endpoints_bindings { export_macro_name: "__export_endpoints_world", default_bindings_module: "openidea_plugin::endpoints_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/workspace@1.19.0": crate::bindings::openidea::plugin::workspace, - "openidea:plugin/editor@1.19.0": crate::bindings::openidea::plugin::editor, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/workspace@1.20.0": crate::bindings::openidea::plugin::workspace, + "openidea:plugin/editor@1.20.0": crate::bindings::openidea::plugin::editor, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, }, }); } @@ -283,16 +283,16 @@ pub mod search_bindings { export_macro_name: "__export_search_world", default_bindings_module: "openidea_plugin::search_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/workspace@1.19.0": crate::bindings::openidea::plugin::workspace, - "openidea:plugin/editor@1.19.0": crate::bindings::openidea::plugin::editor, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/workspace@1.20.0": crate::bindings::openidea::plugin::workspace, + "openidea:plugin/editor@1.20.0": crate::bindings::openidea::plugin::editor, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, }, }); } /// The plugin API version this SDK targets. -pub const API_VERSION: &str = "1.19"; +pub const API_VERSION: &str = "1.20"; /// A plugin. One instance lives as long as the plugin's Wasm instance (until /// it is disabled, crashes or is reclaimed when idle). @@ -1611,7 +1611,7 @@ pub mod run_configurations_bindings { pub mod launch_configurations_bindings { wit_bindgen::generate!({ world: "launch-configurations-provider", path: "wit", pub_export_macro: true, export_macro_name: "__export_launch_configurations_world", default_bindings_module: "openidea_plugin::launch_configurations_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } #[cfg(target_arch = "wasm32")] @@ -1620,8 +1620,8 @@ pub mod execution_configurations_bindings { wit_bindgen::generate!({ world: "execution-configurations-provider", path: "wit", pub_export_macro: true, export_macro_name: "__export_execution_configurations_world", default_bindings_module: "openidea_plugin::execution_configurations_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/run@1.19.0": crate::bindings::openidea::plugin::run, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/run@1.20.0": crate::bindings::openidea::plugin::run, }, }); } @@ -1630,7 +1630,7 @@ pub mod execution_configurations_bindings { pub mod test_results_bindings { wit_bindgen::generate!({ world: "test-results-provider", path: "wit", pub_export_macro: true, export_macro_name: "__export_tests_world", default_bindings_module: "openidea_plugin::test_results_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } #[doc(hidden)] @@ -1692,7 +1692,7 @@ pub mod language_features; pub mod language_features_bindings { wit_bindgen::generate!({world: "editor-language-features", path: "wit", pub_export_macro: true, export_macro_name: "__export_language_features_world", default_bindings_module: "openidea_plugin::language_features_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -1724,7 +1724,7 @@ fn gutter_actions(doc: $crate::language_features_bindings::exports::openidea::pl pub mod injections_bindings { wit_bindgen::generate!({world: "language-injections", path: "wit", pub_export_macro: true, export_macro_name: "__export_injections_world", default_bindings_module: "openidea_plugin::injections_bindings", - with: { "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types }, + with: { "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types }, }); } @@ -1754,8 +1754,8 @@ pub mod mcp_bindings { wit_bindgen::generate!({ world: "mcp-tools", path: "wit", pub_export_macro: true, export_macro_name: "__export_mcp_world", default_bindings_module: "openidea_plugin::mcp_bindings", with: { - "openidea:plugin/types@1.19.0": crate::bindings::openidea::plugin::types, - "openidea:plugin/invocation@1.19.0": crate::bindings::openidea::plugin::invocation, + "openidea:plugin/types@1.20.0": crate::bindings::openidea::plugin::types, + "openidea:plugin/invocation@1.20.0": crate::bindings::openidea::plugin::invocation, }, }); } diff --git a/sdk/rust/openidea-plugin/src/mock.rs b/sdk/rust/openidea-plugin/src/mock.rs index b7d7dfffe..b7873e32b 100644 --- a/sdk/rust/openidea-plugin/src/mock.rs +++ b/sdk/rust/openidea-plugin/src/mock.rs @@ -98,6 +98,8 @@ struct Editor { selections: Vec<Range>, } +type DatabaseSchemaKey = (String, String, Option<String>, String, String); + #[derive(Default)] struct State { capabilities: Vec<String>, @@ -199,6 +201,7 @@ struct State { database_sources: BTreeMap<(String, String), PluginDataSource>, database_credentials: BTreeSet<(String, String)>, database_connections: Vec<(String, String)>, + database_schemas: BTreeMap<DatabaseSchemaKey, DatabaseTableSchema>, lsp_responses: BTreeMap<(String, String), String>, lsp_requests: Vec<MockServerMessage>, lsp_notifications: Vec<MockServerMessage>, @@ -319,6 +322,13 @@ impl MockHost { self.state.borrow_mut().owned_commands.insert(stable); } + /// Supplies metadata of an already connected table, without any credentials or row data. + pub fn set_database_table_schema(&self, root: &str, table: &DatabaseTableRef, schema: DatabaseTableSchema) { + self.state.borrow_mut().database_schemas.insert( + (root.into(), table.source_id.clone(), table.catalog.clone(), table.schema.clone(), table.table.clone()), + schema, + ); + } /// Supplies search responses without duplicating the IDE search engine. pub fn on_search(&self, handler: impl Fn(&TextQuery, u32) -> Result<TextSearch, Error> + 'static) { self.state.borrow_mut().search = Some(Box::new(handler)); @@ -2693,6 +2703,24 @@ pub mod current { Ok(()) } + pub fn database_table_schema(project: &ProjectRes, table: &DatabaseTableRef) -> Result<DatabaseTableSchema, Error> { + with(|s| { + require(s, "database.schema")?; + if s.restricted { + return Err(Error::Denied("project is not trusted".into())); + } + s.database_schemas + .get(&( + project.root.clone(), + table.source_id.clone(), + table.catalog.clone(), + table.schema.clone(), + table.table.clone(), + )) + .cloned() + .ok_or_else(|| Error::NotFound("no connected table".into())) + }) + } pub fn database_upsert(project: &ProjectRes, source: &PluginDataSource) -> Result<(), Error> { with(|s| { require(s, "database.sources")?; diff --git a/sdk/rust/openidea-plugin/src/types.rs b/sdk/rust/openidea-plugin/src/types.rs index a70e85cab..d001718b8 100644 --- a/sdk/rust/openidea-plugin/src/types.rs +++ b/sdk/rust/openidea-plugin/src/types.rs @@ -986,3 +986,47 @@ pub struct PluginDataSource { pub url: Option<String>, pub options: Vec<(String, String)>, } + +/// Identifies a table in an already connected project data source (API 1.20). +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DatabaseTableRef { + pub source_id: String, + pub catalog: Option<String>, + pub schema: String, + pub table: String, +} +/// Read-only column metadata. No row values or connection settings. +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DatabaseColumn { + pub name: String, + pub data_type: String, + pub nullable: bool, + pub default_value: Option<String>, + pub primary_key: bool, + pub comment: Option<String>, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DatabaseIndex { + pub name: String, + pub unique: bool, + pub columns: Vec<String>, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DatabaseForeignKey { + pub columns: Vec<String>, + pub referenced_schema: String, + pub referenced_table: String, + pub referenced_columns: Vec<String>, +} +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DatabaseTableSchema { + pub comment: Option<String>, + pub columns: Vec<DatabaseColumn>, + pub indexes: Vec<DatabaseIndex>, + pub foreign_keys: Vec<DatabaseForeignKey>, +} diff --git a/sdk/rust/openidea-plugin/tests/api20_database_schema.rs b/sdk/rust/openidea-plugin/tests/api20_database_schema.rs new file mode 100644 index 000000000..1bf3f788b --- /dev/null +++ b/sdk/rust/openidea-plugin/tests/api20_database_schema.rs @@ -0,0 +1,41 @@ +use openidea_plugin::{DatabaseColumn, DatabaseTableRef, DatabaseTableSchema, Error, host, mock::MockHost}; + +#[test] +fn schema_reads_are_project_scoped_separately_granted_and_never_manage_sources() { + let mock = MockHost::install().with_capabilities(&["database.schema", "project.read"]); + mock.set_project_root(Some("/project")); + let table = DatabaseTableRef { + source_id: "user-created:inventory".into(), + catalog: None, + schema: "public".into(), + table: "users".into(), + }; + let schema = DatabaseTableSchema { + columns: vec![DatabaseColumn { + name: "id".into(), + data_type: "BIGINT".into(), + primary_key: true, + ..Default::default() + }], + ..Default::default() + }; + mock.set_database_table_schema("/project", &table, schema.clone()); + let project = host::projects().unwrap().remove(0); + assert_eq!(project.database_table_schema(&table).unwrap(), schema); + assert!(matches!(project.data_sources(), Err(Error::Denied(_)))); + mock.add_project("/other"); + let other = host::projects().unwrap().into_iter().find(|p| p.root().ok().as_deref() == Some("/other")).unwrap(); + assert!(matches!(other.database_table_schema(&table), Err(Error::NotFound(_)))); + mock.set_restricted(true); + assert!(matches!(project.database_table_schema(&table), Err(Error::Denied(_)))); + mock.set_restricted(false); + assert!(project.database_table_schema(&DatabaseTableRef { table: "missing".into(), ..table.clone() }).is_err()); +} + +#[test] +fn project_read_and_source_ownership_do_not_grant_schema_reads() { + let mock = MockHost::install().with_capabilities(&["project.read", "database.sources"]); + mock.set_project_root(Some("/project")); + let p = host::projects().unwrap().remove(0); + assert!(matches!(p.database_table_schema(&DatabaseTableRef::default()), Err(Error::Denied(_)))); +} diff --git a/sdk/rust/openidea-plugin/wit/agents.wit b/sdk/rust/openidea-plugin/wit/agents.wit index 650bcf31a..d5b0b101a 100644 --- a/sdk/rust/openidea-plugin/wit/agents.wit +++ b/sdk/rust/openidea-plugin/wit/agents.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Forking recorded native agent sessions into new tasks (API 1.18). Requires /// the `agents` capability. The session must belong to the invoking window's diff --git a/sdk/rust/openidea-plugin/wit/commit.wit b/sdk/rust/openidea-plugin/wit/commit.wit index 6cc466bea..94a1c2882 100644 --- a/sdk/rust/openidea-plugin/wit/commit.wit +++ b/sdk/rust/openidea-plugin/wit/commit.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// The commit being prepared in the window the current command or event came /// from (the Commit tool window, or the Commit dialog while it is open): the diff --git a/sdk/rust/openidea-plugin/wit/completion-list.wit b/sdk/rust/openidea-plugin/wit/completion-list.wit index 2f72c39a5..34d283648 100644 --- a/sdk/rust/openidea-plugin/wit/completion-list.wit +++ b/sdk/rust/openidea-plugin/wit/completion-list.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (API 1.16, world `plugin-completion-list`): completion that /// can say its list is incomplete. A plugin exporting it is called instead of diff --git a/sdk/rust/openidea-plugin/wit/database.wit b/sdk/rust/openidea-plugin/wit/database.wit index dd31ba096..0284b0e9d 100644 --- a/sdk/rust/openidea-plugin/wit/database.wit +++ b/sdk/rust/openidea-plugin/wit/database.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Plugin-owned project data sources. Requires database.sources and project trust. /// Runs on the Database subsystem's host, including on remote project servers. @@ -31,4 +31,42 @@ interface database { /// Requests the project's usual connection/introspection in the invoking window. /// Invalid outside a command/event of that project's window. connect: func(project: borrow<project>, id: string) -> result<_, error>; + + /// A table/view in an already connected data source of this project (API 1.20). + /// source-id is the host's connection target id, including its database suffix. + record table-ref { + source-id: string, + catalog: option<string>, + schema: string, + table: string, + } + record column-schema { + name: string, + data-type: string, + nullable: bool, + default-value: option<string>, + primary-key: bool, + comment: option<string>, + } + record index-schema { + name: string, + unique: bool, + columns: list<string>, + } + record foreign-key-schema { + columns: list<string>, + referenced-schema: string, + referenced-table: string, + referenced-columns: list<string>, + } + record table-schema { + comment: option<string>, + columns: list<column-schema>, + indexes: list<index-schema>, + foreign-keys: list<foreign-key-schema>, + } + /// Read metadata of any already connected project source, including user-owned + /// sources. Requires the separate database.schema grant and a trusted project. + /// Never connects a source, returns credentials/rows, or executes caller SQL. + describe-table: func(project: borrow<project>, table: table-ref) -> result<table-schema, error>; } diff --git a/sdk/rust/openidea-plugin/wit/decorations.wit b/sdk/rust/openidea-plugin/wit/decorations.wit index 6499138ed..d7bc07393 100644 --- a/sdk/rust/openidea-plugin/wit/decorations.wit +++ b/sdk/rust/openidea-plugin/wit/decorations.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Editor and project-tree decorations (API 1.4). Requires project.read. An editor set /// follows its file: the file's own project, or the nearest one when it is outside them all. diff --git a/sdk/rust/openidea-plugin/wit/details.wit b/sdk/rust/openidea-plugin/wit/details.wit index b99936ec3..ec0948bc0 100644 --- a/sdk/rust/openidea-plugin/wit/details.wit +++ b/sdk/rust/openidea-plugin/wit/details.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// What the pane beside the Services tree shows for a plugin's node. interface detail-types { diff --git a/sdk/rust/openidea-plugin/wit/diagnostics.wit b/sdk/rust/openidea-plugin/wit/diagnostics.wit index b998d085c..9f4d97d97 100644 --- a/sdk/rust/openidea-plugin/wit/diagnostics.wit +++ b/sdk/rust/openidea-plugin/wit/diagnostics.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-diagnostics`): problems in the current, /// possibly unsaved document, for the languages declared with the diff --git a/sdk/rust/openidea-plugin/wit/endpoints.wit b/sdk/rust/openidea-plugin/wit/endpoints.wit index 1308734d5..b10ed5d8c 100644 --- a/sdk/rust/openidea-plugin/wit/endpoints.wit +++ b/sdk/rust/openidea-plugin/wit/endpoints.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// HTTP endpoints found in a project (`[[contributes.endpoints]]`). interface endpoints-provider { diff --git a/sdk/rust/openidea-plugin/wit/events.wit b/sdk/rust/openidea-plugin/wit/events.wit index 4f0b84817..740294de6 100644 --- a/sdk/rust/openidea-plugin/wit/events.wit +++ b/sdk/rust/openidea-plugin/wit/events.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Workbench events, delivered in batches to `event-handler.handle`. interface events { diff --git a/sdk/rust/openidea-plugin/wit/exports.wit b/sdk/rust/openidea-plugin/wit/exports.wit index 090b0cf46..96592f800 100644 --- a/sdk/rust/openidea-plugin/wit/exports.wit +++ b/sdk/rust/openidea-plugin/wit/exports.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; interface lifecycle { use types.{context, error}; diff --git a/sdk/rust/openidea-plugin/wit/extensions.wit b/sdk/rust/openidea-plugin/wit/extensions.wit index 80cbcc246..f5e081470 100644 --- a/sdk/rust/openidea-plugin/wit/extensions.wit +++ b/sdk/rust/openidea-plugin/wit/extensions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// What other plugins contributed to the extension points this plugin declares /// (`[[extension-points]]` in `plugin.toml`; the contributors list this plugin diff --git a/sdk/rust/openidea-plugin/wit/file-actions.wit b/sdk/rust/openidea-plugin/wit/file-actions.wit index eef30c840..0a0f66690 100644 --- a/sdk/rust/openidea-plugin/wit/file-actions.wit +++ b/sdk/rust/openidea-plugin/wit/file-actions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-file-actions`): quick fixes and /// refactorings that create, rename or delete files, next to the text edits diff --git a/sdk/rust/openidea-plugin/wit/fs.wit b/sdk/rust/openidea-plugin/wit/fs.wit index d9490a687..5eb436bd8 100644 --- a/sdk/rust/openidea-plugin/wit/fs.wit +++ b/sdk/rust/openidea-plugin/wit/fs.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Files outside the open projects: the configuration of the program a /// plugin integrates with, a tool installed elsewhere, a licence file. diff --git a/sdk/rust/openidea-plugin/wit/host.wit b/sdk/rust/openidea-plugin/wit/host.wit index 2448e3c78..1e131c637 100644 --- a/sdk/rust/openidea-plugin/wit/host.wit +++ b/sdk/rust/openidea-plugin/wit/host.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Writes to the IDE log, tagged with the plugin id. interface log { diff --git a/sdk/rust/openidea-plugin/wit/hover-actions.wit b/sdk/rust/openidea-plugin/wit/hover-actions.wit index eb9451f9e..070c66a2b 100644 --- a/sdk/rust/openidea-plugin/wit/hover-actions.wit +++ b/sdk/rust/openidea-plugin/wit/hover-actions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-hover-actions`): clickable actions rendered /// at the left edge of a line and revealed while the pointer is in the leftmost diff --git a/sdk/rust/openidea-plugin/wit/hover.wit b/sdk/rust/openidea-plugin/wit/hover.wit index b452036ed..c9be10359 100644 --- a/sdk/rust/openidea-plugin/wit/hover.wit +++ b/sdk/rust/openidea-plugin/wit/hover.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-hover`): Markdown added to the hover of /// documents of the languages declared with the `hover` provider kind, diff --git a/sdk/rust/openidea-plugin/wit/indexing.wit b/sdk/rust/openidea-plugin/wit/indexing.wit index dea32cdca..7453f3ffe 100644 --- a/sdk/rust/openidea-plugin/wit/indexing.wit +++ b/sdk/rust/openidea-plugin/wit/indexing.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Cross-file associations a plugin publishes for the files it declares under /// `[[contributes.documentIndexers]]`. The host calls `index` in cancellable diff --git a/sdk/rust/openidea-plugin/wit/injections.wit b/sdk/rust/openidea-plugin/wit/injections.wit index 859c6345c..10608d5f6 100644 --- a/sdk/rust/openidea-plugin/wit/injections.wit +++ b/sdk/rust/openidea-plugin/wit/injections.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Embedded languages. The host routes plugin providers and configured language /// servers inside these ranges, preserving host-document UTF-16 coordinates. diff --git a/sdk/rust/openidea-plugin/wit/inlay.wit b/sdk/rust/openidea-plugin/wit/inlay.wit index 93b3bce95..b6d1498e6 100644 --- a/sdk/rust/openidea-plugin/wit/inlay.wit +++ b/sdk/rust/openidea-plugin/wit/inlay.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-inlay-hints`): inline hints in documents of /// the languages declared with the `inlay-hints` provider kind, including diff --git a/sdk/rust/openidea-plugin/wit/io.wit b/sdk/rust/openidea-plugin/wit/io.wit index a3e830eda..d9f3354a4 100644 --- a/sdk/rust/openidea-plugin/wit/io.wit +++ b/sdk/rust/openidea-plugin/wit/io.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Problems in files, shown in the editor and the Problems view. interface diagnostics { diff --git a/sdk/rust/openidea-plugin/wit/language-features.wit b/sdk/rust/openidea-plugin/wit/language-features.wit index 1ee1f7ab2..1a6a722d4 100644 --- a/sdk/rust/openidea-plugin/wit/language-features.wit +++ b/sdk/rust/openidea-plugin/wit/language-features.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Additional language features, called only for declared API 1.4 provider kinds. /// Editor calls have a 50 ms soft / 500 ms hard budget; formatting has 5 seconds. diff --git a/sdk/rust/openidea-plugin/wit/mcp.wit b/sdk/rust/openidea-plugin/wit/mcp.wit index 633daa132..c1de914ec 100644 --- a/sdk/rust/openidea-plugin/wit/mcp.wit +++ b/sdk/rust/openidea-plugin/wit/mcp.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Discovery of the IDE's built-in MCP server; never exposes its URL or token. interface mcp { diff --git a/sdk/rust/openidea-plugin/wit/plugin.wit b/sdk/rust/openidea-plugin/wit/plugin.wit index 86ccc2b1e..af3b12263 100644 --- a/sdk/rust/openidea-plugin/wit/plugin.wit +++ b/sdk/rust/openidea-plugin/wit/plugin.wit @@ -8,7 +8,7 @@ /// `fs` and `workspace`, and everything else goes through the imports below, /// gated by the capabilities granted in `plugin.toml` (a missing one returns /// `error::denied`). -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; world plugin { import log; diff --git a/sdk/rust/openidea-plugin/wit/providers.wit b/sdk/rust/openidea-plugin/wit/providers.wit index 6ff67abeb..2fb49ff34 100644 --- a/sdk/rust/openidea-plugin/wit/providers.wit +++ b/sdk/rust/openidea-plugin/wit/providers.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Editor features a plugin provides for the languages it declares under /// `[[contributes.providers]]` (the host calls only declared kinds). They run diff --git a/sdk/rust/openidea-plugin/wit/run-targets.wit b/sdk/rust/openidea-plugin/wit/run-targets.wit index 76727c8f7..2495bc1ce 100644 --- a/sdk/rust/openidea-plugin/wit/run-targets.wit +++ b/sdk/rust/openidea-plugin/wit/run-targets.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Project-scoped targets owned by the registering plugin (API 1.4). interface run-targets { diff --git a/sdk/rust/openidea-plugin/wit/run.wit b/sdk/rust/openidea-plugin/wit/run.wit index 799bb3bd5..6bfb18b74 100644 --- a/sdk/rust/openidea-plugin/wit/run.wit +++ b/sdk/rust/openidea-plugin/wit/run.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Launches this plugin's configurations in the invoking window's Run tool window. interface run { diff --git a/sdk/rust/openidea-plugin/wit/search.wit b/sdk/rust/openidea-plugin/wit/search.wit index 1aa091d73..775cc0341 100644 --- a/sdk/rust/openidea-plugin/wit/search.wit +++ b/sdk/rust/openidea-plugin/wit/search.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// On-demand results for `[[contributes.searchCategories]]`. Optional, API 1.13. interface search-provider { diff --git a/sdk/rust/openidea-plugin/wit/semantic.wit b/sdk/rust/openidea-plugin/wit/semantic.wit index 90f7de72b..551db318d 100644 --- a/sdk/rust/openidea-plugin/wit/semantic.wit +++ b/sdk/rust/openidea-plugin/wit/semantic.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-semantic-tokens`): semantic colouring of /// documents of the languages declared with the `semantic-tokens` provider diff --git a/sdk/rust/openidea-plugin/wit/types.wit b/sdk/rust/openidea-plugin/wit/types.wit index c2202811f..d28702152 100644 --- a/sdk/rust/openidea-plugin/wit/types.wit +++ b/sdk/rust/openidea-plugin/wit/types.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Shared types. Positions are 0-based lines and UTF-16 code unit columns, /// as in the editor and LSP. diff --git a/sdk/rust/openidea-plugin/wit/views.wit b/sdk/rust/openidea-plugin/wit/views.wit index 32cd76771..973341847 100644 --- a/sdk/rust/openidea-plugin/wit/views.wit +++ b/sdk/rust/openidea-plugin/wit/views.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Declarative views: tool windows declared /// under `[[contributes.views]]` and custom editors under diff --git a/sdk/rust/openidea-plugin/wit/workspace.wit b/sdk/rust/openidea-plugin/wit/workspace.wit index 7f1088cb4..d96234945 100644 --- a/sdk/rust/openidea-plugin/wit/workspace.wit +++ b/sdk/rust/openidea-plugin/wit/workspace.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; interface workspace { use types.{error, location}; diff --git a/src/features/database/treeMenu.ts b/src/features/database/treeMenu.ts index 230e82dfa..c79c9a9a1 100644 --- a/src/features/database/treeMenu.ts +++ b/src/features/database/treeMenu.ts @@ -1,5 +1,6 @@ /** Menus of the Database tool window, laid out like IDEA's (New ▸, Copy/Paste ▸, SQL Scripts ▸ …). */ import { choosePath } from "@/platform/choosePath"; +import { pluginDatabaseTableMenuItems } from "@/features/plugins/uiPoints"; import { tx } from "@/platform/i18n"; import type { MenuItem } from "@/ui"; import { notifications } from "@/workbench/contributions"; @@ -194,6 +195,24 @@ function batchSourceMenu(sources: Extract<DbNode, { kind: "source" }>[]): MenuIt /** Context menu of a tree node (`null`: the empty area). */ export function nodeMenu(n: DbNode | null, selection: readonly DbNode[] = []): MenuItem[] { + const builtin = builtinNodeMenu(n, selection); + if (n?.kind !== "table") return builtin; + const selected = selection.some((node) => node.key === n.key) ? selection : [n]; + // Mixed selections cannot be represented as a table command; do not silently drop nodes. + if (!selected.every((node) => node.kind === "table")) return builtin; + const tables = selected.map((node) => ({ + sourceId: node.id, + catalog: node.catalog ?? null, + schema: node.schema, + table: node.table.name, + kind: node.table.kind, + driver: sourceById(node.id)?.driver ?? "", + })); + const plugins = pluginDatabaseTableMenuItems(tables); + return plugins.length ? [...builtin, sep, ...plugins] : builtin; +} + +function builtinNodeMenu(n: DbNode | null, selection: readonly DbNode[] = []): MenuItem[] { if (!n) return [{ label: "New", icon: "plus", submenu: newMenu() }]; if (n.kind === "workspace") return [ diff --git a/src/features/plugins/__tests__/databaseMenus.test.tsx b/src/features/plugins/__tests__/databaseMenus.test.tsx new file mode 100644 index 000000000..b61307c12 --- /dev/null +++ b/src/features/plugins/__tests__/databaseMenus.test.tsx @@ -0,0 +1,99 @@ +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import type { PluginInfo } from "@/bindings"; +import { registerAction } from "@/platform/actions"; +import { nodeMenu } from "@/features/database/treeMenu"; +import { useDatabase } from "@/features/database/store"; +import type { DbNode } from "@/features/database/nodes"; +import { defineBuiltinUiPoints } from "../points"; +import { clearUiContributions, syncUiContributions } from "../projection"; +import { pluginDatabaseTableMenuItems, type DatabaseTableContext } from "../uiPoints"; + +const initialDatabase = useDatabase.getState(); +let stop: () => void; +let offs: (() => void)[]; +beforeEach(() => { + stop = defineBuiltinUiPoints(); + offs = []; +}); +afterEach(() => { + useDatabase.setState(initialDatabase, true); + clearUiContributions(); + stop(); + offs.forEach((off) => off()); +}); +const plugin = { id: "mapper", name: "Mapper generator", enabled: true, status: "active", icon: null } as PluginInfo; +const table: DatabaseTableContext = { + sourceId: "pg:inventory", + catalog: null, + schema: "public", + table: "users", + kind: "table", + driver: "postgres", +}; +function contribute(when?: string) { + offs.push(registerAction({ id: "plugin.mapper.generate", title: "Generate mapper", run: () => {} })); + syncUiContributions( + [ + { + pluginId: "mapper", + point: "menus", + key: "database.table.context/generate", + decl: { + menu: "database.table.context", + command: "generate", + submenu: "Generate", + when, + }, + }, + ], + [plugin], + ); +} +describe("database table plugin menu", () => { + it("passes only non-secret table identities and checks when for every selected table", () => { + contribute("databaseDriver == postgres && databaseObjectKind == table && databaseSelectionCount == 1"); + const [entry] = pluginDatabaseTableMenuItems([table]); + expect(entry).toEqual({ + kind: "action", + action: "plugin.mapper.generate", + arg: JSON.stringify({ tables: [table] }), + }); + expect(pluginDatabaseTableMenuItems([])).toEqual([]); + expect(pluginDatabaseTableMenuItems([table, { ...table, table: "orders" }])).toEqual([]); + expect(pluginDatabaseTableMenuItems([{ ...table, kind: "view" }])).toEqual([]); + expect(pluginDatabaseTableMenuItems([{ ...table, driver: "mysql" }])).toEqual([]); + }); + it("strips extra fields instead of serializing connection settings", () => { + contribute(); + const injected = { ...table, password: "do-not-send", host: "private-host", url: "private-url" }; + const [entry] = pluginDatabaseTableMenuItems([injected]); + expect(entry).toMatchObject({ arg: JSON.stringify({ tables: [table] }) }); + }); + it("appends commands to built-in table menus and retains a multi-catalog selection", () => { + contribute(); + useDatabase.setState({ sources: [{ id: "duck", name: "Local", driver: "jdbc", vendor: "duckdb" }] }); + const a: DbNode = { + kind: "table", + key: "duck/a/main/users", + id: "duck", + catalog: "a", + schema: "main", + table: { name: "users", kind: "table" }, + }; + const b: DbNode = { ...a, key: "duck/b/main/users", catalog: "b" }; + const items = nodeMenu(a, [a, b]); + expect(items.length).toBeGreaterThan(1); + const entry = items.at(-1)!; + expect(entry).toMatchObject({ action: "plugin.mapper.generate" }); + if (entry.kind !== "action") throw new Error("expected command"); + expect(JSON.parse(entry.arg as string).tables).toEqual([ + { sourceId: "duck", catalog: "a", schema: "main", table: "users", kind: "table", driver: "jdbc" }, + { sourceId: "duck", catalog: "b", schema: "main", table: "users", kind: "table", driver: "jdbc" }, + ]); + expect( + nodeMenu(a, [{ kind: "schema", key: "duck/main", id: "duck", schema: "main" }, a]).some( + (item) => item.kind === "action" && item.action === "plugin.mapper.generate", + ), + ).toBe(false); + }); +}); diff --git a/src/features/plugins/uiPoints.tsx b/src/features/plugins/uiPoints.tsx index a93cac908..61c7cee3f 100644 --- a/src/features/plugins/uiPoints.tsx +++ b/src/features/plugins/uiPoints.tsx @@ -96,6 +96,7 @@ interface MenuDecl { | "commit.message" | "services.context" | "services.toolbar" + | "database.table.context" | "openIn"; view?: string | null; command: string; @@ -187,6 +188,53 @@ export function pluginViewItemMenuItems(pluginId: string, view: string, key: str return flattenSingleGroups(out); } +/** Non-secret table context passed to Database table menu commands (API 1.20). */ +export interface DatabaseTableContext { + sourceId: string; + catalog: string | null; + schema: string; + table: string; + kind: string; + driver: string; +} + +/** The right-clicked table is included in selection by the Database tree. */ +export function pluginDatabaseTableMenuItems(tables: readonly DatabaseTableContext[]): MenuItem[] { + if (!tables.length) return []; + const out: MenuItem[] = []; + const groups = new Map<string, MenuItem[]>(); + // Explicitly pick non-secret fields; never forward a DataSource or DbNode. + const arg = JSON.stringify({ + tables: tables.map(({ sourceId, catalog, schema, table, kind, driver }) => ({ + sourceId, + catalog, + schema, + table, + kind, + driver, + })), + }); + for (const { pluginId, decl } of contextItems.values()) { + if (decl.menu !== "database.table.context") continue; + if ( + !tables.every((table) => + evaluateWhen(decl.when ?? undefined, { + ...getContext(), + databaseDriver: table.driver, + databaseObjectKind: table.kind, + databaseSchema: table.schema, + databaseTable: table.table, + databaseSelectionCount: tables.length, + }), + ) + ) + continue; + const action = pluginActionId(pluginId, decl.command); + if (getAction(action)) addGrouped(out, groups, pluginId, decl.submenu, { kind: "action", action, arg }); + } + return flattenSingleGroups(out); +} + /** The when keys of one selected service. */ export function serviceWhenContext(service: ServiceContext, count: number) { return { diff --git a/wit/agents.wit b/wit/agents.wit index 650bcf31a..d5b0b101a 100644 --- a/wit/agents.wit +++ b/wit/agents.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Forking recorded native agent sessions into new tasks (API 1.18). Requires /// the `agents` capability. The session must belong to the invoking window's diff --git a/wit/commit.wit b/wit/commit.wit index 6cc466bea..94a1c2882 100644 --- a/wit/commit.wit +++ b/wit/commit.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// The commit being prepared in the window the current command or event came /// from (the Commit tool window, or the Commit dialog while it is open): the diff --git a/wit/completion-list.wit b/wit/completion-list.wit index 2f72c39a5..34d283648 100644 --- a/wit/completion-list.wit +++ b/wit/completion-list.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (API 1.16, world `plugin-completion-list`): completion that /// can say its list is incomplete. A plugin exporting it is called instead of diff --git a/wit/database.wit b/wit/database.wit index dd31ba096..0284b0e9d 100644 --- a/wit/database.wit +++ b/wit/database.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Plugin-owned project data sources. Requires database.sources and project trust. /// Runs on the Database subsystem's host, including on remote project servers. @@ -31,4 +31,42 @@ interface database { /// Requests the project's usual connection/introspection in the invoking window. /// Invalid outside a command/event of that project's window. connect: func(project: borrow<project>, id: string) -> result<_, error>; + + /// A table/view in an already connected data source of this project (API 1.20). + /// source-id is the host's connection target id, including its database suffix. + record table-ref { + source-id: string, + catalog: option<string>, + schema: string, + table: string, + } + record column-schema { + name: string, + data-type: string, + nullable: bool, + default-value: option<string>, + primary-key: bool, + comment: option<string>, + } + record index-schema { + name: string, + unique: bool, + columns: list<string>, + } + record foreign-key-schema { + columns: list<string>, + referenced-schema: string, + referenced-table: string, + referenced-columns: list<string>, + } + record table-schema { + comment: option<string>, + columns: list<column-schema>, + indexes: list<index-schema>, + foreign-keys: list<foreign-key-schema>, + } + /// Read metadata of any already connected project source, including user-owned + /// sources. Requires the separate database.schema grant and a trusted project. + /// Never connects a source, returns credentials/rows, or executes caller SQL. + describe-table: func(project: borrow<project>, table: table-ref) -> result<table-schema, error>; } diff --git a/wit/decorations.wit b/wit/decorations.wit index 6499138ed..d7bc07393 100644 --- a/wit/decorations.wit +++ b/wit/decorations.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Editor and project-tree decorations (API 1.4). Requires project.read. An editor set /// follows its file: the file's own project, or the nearest one when it is outside them all. diff --git a/wit/details.wit b/wit/details.wit index b99936ec3..ec0948bc0 100644 --- a/wit/details.wit +++ b/wit/details.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// What the pane beside the Services tree shows for a plugin's node. interface detail-types { diff --git a/wit/diagnostics.wit b/wit/diagnostics.wit index b998d085c..9f4d97d97 100644 --- a/wit/diagnostics.wit +++ b/wit/diagnostics.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-diagnostics`): problems in the current, /// possibly unsaved document, for the languages declared with the diff --git a/wit/endpoints.wit b/wit/endpoints.wit index 1308734d5..b10ed5d8c 100644 --- a/wit/endpoints.wit +++ b/wit/endpoints.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// HTTP endpoints found in a project (`[[contributes.endpoints]]`). interface endpoints-provider { diff --git a/wit/events.wit b/wit/events.wit index 4f0b84817..740294de6 100644 --- a/wit/events.wit +++ b/wit/events.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Workbench events, delivered in batches to `event-handler.handle`. interface events { diff --git a/wit/exports.wit b/wit/exports.wit index 090b0cf46..96592f800 100644 --- a/wit/exports.wit +++ b/wit/exports.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; interface lifecycle { use types.{context, error}; diff --git a/wit/extensions.wit b/wit/extensions.wit index 80cbcc246..f5e081470 100644 --- a/wit/extensions.wit +++ b/wit/extensions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// What other plugins contributed to the extension points this plugin declares /// (`[[extension-points]]` in `plugin.toml`; the contributors list this plugin diff --git a/wit/file-actions.wit b/wit/file-actions.wit index eef30c840..0a0f66690 100644 --- a/wit/file-actions.wit +++ b/wit/file-actions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-file-actions`): quick fixes and /// refactorings that create, rename or delete files, next to the text edits diff --git a/wit/fs.wit b/wit/fs.wit index d9490a687..5eb436bd8 100644 --- a/wit/fs.wit +++ b/wit/fs.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Files outside the open projects: the configuration of the program a /// plugin integrates with, a tool installed elsewhere, a licence file. diff --git a/wit/host.wit b/wit/host.wit index 2448e3c78..1e131c637 100644 --- a/wit/host.wit +++ b/wit/host.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Writes to the IDE log, tagged with the plugin id. interface log { diff --git a/wit/hover-actions.wit b/wit/hover-actions.wit index eb9451f9e..070c66a2b 100644 --- a/wit/hover-actions.wit +++ b/wit/hover-actions.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-hover-actions`): clickable actions rendered /// at the left edge of a line and revealed while the pointer is in the leftmost diff --git a/wit/hover.wit b/wit/hover.wit index b452036ed..c9be10359 100644 --- a/wit/hover.wit +++ b/wit/hover.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-hover`): Markdown added to the hover of /// documents of the languages declared with the `hover` provider kind, diff --git a/wit/indexing.wit b/wit/indexing.wit index dea32cdca..7453f3ffe 100644 --- a/wit/indexing.wit +++ b/wit/indexing.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Cross-file associations a plugin publishes for the files it declares under /// `[[contributes.documentIndexers]]`. The host calls `index` in cancellable diff --git a/wit/injections.wit b/wit/injections.wit index 859c6345c..10608d5f6 100644 --- a/wit/injections.wit +++ b/wit/injections.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Embedded languages. The host routes plugin providers and configured language /// servers inside these ranges, preserving host-document UTF-16 coordinates. diff --git a/wit/inlay.wit b/wit/inlay.wit index 93b3bce95..b6d1498e6 100644 --- a/wit/inlay.wit +++ b/wit/inlay.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-inlay-hints`): inline hints in documents of /// the languages declared with the `inlay-hints` provider kind, including diff --git a/wit/io.wit b/wit/io.wit index a3e830eda..d9f3354a4 100644 --- a/wit/io.wit +++ b/wit/io.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Problems in files, shown in the editor and the Problems view. interface diagnostics { diff --git a/wit/language-features.wit b/wit/language-features.wit index 1ee1f7ab2..1a6a722d4 100644 --- a/wit/language-features.wit +++ b/wit/language-features.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Additional language features, called only for declared API 1.4 provider kinds. /// Editor calls have a 50 ms soft / 500 ms hard budget; formatting has 5 seconds. diff --git a/wit/mcp.wit b/wit/mcp.wit index 633daa132..c1de914ec 100644 --- a/wit/mcp.wit +++ b/wit/mcp.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Discovery of the IDE's built-in MCP server; never exposes its URL or token. interface mcp { diff --git a/wit/plugin.wit b/wit/plugin.wit index 86ccc2b1e..af3b12263 100644 --- a/wit/plugin.wit +++ b/wit/plugin.wit @@ -8,7 +8,7 @@ /// `fs` and `workspace`, and everything else goes through the imports below, /// gated by the capabilities granted in `plugin.toml` (a missing one returns /// `error::denied`). -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; world plugin { import log; diff --git a/wit/providers.wit b/wit/providers.wit index 6ff67abeb..2fb49ff34 100644 --- a/wit/providers.wit +++ b/wit/providers.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Editor features a plugin provides for the languages it declares under /// `[[contributes.providers]]` (the host calls only declared kinds). They run diff --git a/wit/run-targets.wit b/wit/run-targets.wit index 76727c8f7..2495bc1ce 100644 --- a/wit/run-targets.wit +++ b/wit/run-targets.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Project-scoped targets owned by the registering plugin (API 1.4). interface run-targets { diff --git a/wit/run.wit b/wit/run.wit index 799bb3bd5..6bfb18b74 100644 --- a/wit/run.wit +++ b/wit/run.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Launches this plugin's configurations in the invoking window's Run tool window. interface run { diff --git a/wit/search.wit b/wit/search.wit index 1aa091d73..775cc0341 100644 --- a/wit/search.wit +++ b/wit/search.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// On-demand results for `[[contributes.searchCategories]]`. Optional, API 1.13. interface search-provider { diff --git a/wit/semantic.wit b/wit/semantic.wit index 90f7de72b..551db318d 100644 --- a/wit/semantic.wit +++ b/wit/semantic.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Optional export (world `plugin-semantic-tokens`): semantic colouring of /// documents of the languages declared with the `semantic-tokens` provider diff --git a/wit/types.wit b/wit/types.wit index c2202811f..d28702152 100644 --- a/wit/types.wit +++ b/wit/types.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Shared types. Positions are 0-based lines and UTF-16 code unit columns, /// as in the editor and LSP. diff --git a/wit/views.wit b/wit/views.wit index 32cd76771..973341847 100644 --- a/wit/views.wit +++ b/wit/views.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; /// Declarative views: tool windows declared /// under `[[contributes.views]]` and custom editors under diff --git a/wit/workspace.wit b/wit/workspace.wit index 7f1088cb4..d96234945 100644 --- a/wit/workspace.wit +++ b/wit/workspace.wit @@ -1,4 +1,4 @@ -package openidea:plugin@1.19.0; +package openidea:plugin@1.20.0; interface workspace { use types.{error, location};