diff --git a/crates/gpui/src/action.rs b/crates/gpui/src/action.rs index 38e94aa356dcb7ea1f0f988d1407471bfc0d3a84..1ab619ff171dbeab8a0843393874e7184320e0db 100644 --- a/crates/gpui/src/action.rs +++ b/crates/gpui/src/action.rs @@ -397,6 +397,16 @@ impl ActionRegistry { .collect::>() } + pub fn action_schema_by_name( + &self, + name: &str, + generator: &mut schemars::SchemaGenerator, + ) -> Option> { + self.by_name + .get(name) + .map(|action_data| (action_data.json_schema)(generator)) + } + pub fn deprecated_aliases(&self) -> &HashMap<&'static str, &'static str> { &self.deprecated_aliases } diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index c969b018f38b54c72e6a8beaeb4730f3b68dd56e..602fd3463a5e058e62c353db922c31d5c465b383 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1876,6 +1876,18 @@ impl App { self.actions.action_schemas(generator) } + /// Get the schema for a specific action by name. + /// Returns `None` if the action is not found. + /// Returns `Some(None)` if the action exists but has no schema. + /// Returns `Some(Some(schema))` if the action exists and has a schema. + pub fn action_schema_by_name( + &self, + name: &str, + generator: &mut schemars::SchemaGenerator, + ) -> Option> { + self.actions.action_schema_by_name(name, generator) + } + /// Get a map from a deprecated action name to the canonical name. pub fn deprecated_actions_to_preferred_actions(&self) -> &HashMap<&'static str, &'static str> { self.actions.deprecated_aliases() diff --git a/crates/json_schema_store/src/json_schema_store.rs b/crates/json_schema_store/src/json_schema_store.rs index ac1b77df0c5be7fea2ca28451d431b8fd61d5859..9a5cc658c99ecba4460077c03d6d8d1b445c3284 100644 --- a/crates/json_schema_store/src/json_schema_store.rs +++ b/crates/json_schema_store/src/json_schema_store.rs @@ -300,6 +300,17 @@ async fn resolve_dynamic_schema( }); task::DebugTaskFile::generate_json_schema(&adapter_schemas) } + "keymap" => cx.update(settings::KeymapFile::generate_json_schema_for_registered_actions), + "action" => { + let normalized_action_name = rest.context("No Action name provided")?; + let action_name = denormalize_action_name(normalized_action_name); + let mut generator = settings::KeymapFile::action_schema_generator(); + let schema = cx + .update(|cx| cx.action_schema_by_name(&action_name, &mut generator)) + .flatten(); + root_schema_from_action_schema(schema, &mut generator).to_value() + } + "tasks" => task::TaskTemplates::generate_json_schema(), _ => { anyhow::bail!("Unrecognized schema: {schema_name}"); }