From 137081f050c766cc2f5a3fbf913a12453912e35d Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sun, 20 Jul 2025 17:22:13 -0600 Subject: [PATCH] Misc code cleanups accumulated while working on other changes (#34787) Release Notes: - N/A --- crates/command_palette/src/command_palette.rs | 2 +- crates/dap/src/registry.rs | 1 + crates/gpui/examples/set_menus.rs | 2 +- crates/gpui/src/app.rs | 4 +++- .../src/migrations/m_2025_04_15/keymap.rs | 2 +- crates/theme/src/schema.rs | 18 ++---------------- crates/util/src/schemars.rs | 1 - 7 files changed, 9 insertions(+), 21 deletions(-) diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index abb8978d5a103fb66f862af6c5ee69beee0f6251..dfaede0dc4c5d2d2ab9f45c1e73713e7d56f189d 100644 --- a/crates/command_palette/src/command_palette.rs +++ b/crates/command_palette/src/command_palette.rs @@ -242,7 +242,7 @@ impl CommandPaletteDelegate { self.selected_ix = cmp::min(self.selected_ix, self.matches.len() - 1); } } - /// + /// Hit count for each command in the palette. /// We only account for commands triggered directly via command palette and not by e.g. keystrokes because /// if a user already knows a keystroke for a command, they are unlikely to use a command palette to look for it. diff --git a/crates/dap/src/registry.rs b/crates/dap/src/registry.rs index 9435b16b924e43406d5ed99c864df78c179f27b1..d56e2f8f34e70dafa0126f793b2f755d09a6854d 100644 --- a/crates/dap/src/registry.rs +++ b/crates/dap/src/registry.rs @@ -46,6 +46,7 @@ impl DapRegistry { let name = adapter.name(); let _previous_value = self.0.write().adapters.insert(name, adapter); } + pub fn add_locator(&self, locator: Arc) { self.0.write().locators.insert(locator.name(), locator); } diff --git a/crates/gpui/examples/set_menus.rs b/crates/gpui/examples/set_menus.rs index 2b302f78f273449b9afeac8cb272a1a8148aaf56..f53fff7c7f7dfca1d2e44faf39347d1716ddad1c 100644 --- a/crates/gpui/examples/set_menus.rs +++ b/crates/gpui/examples/set_menus.rs @@ -34,7 +34,7 @@ fn main() { }); } -// Associate actions using the `actions!` macro (or `impl_actions!` macro) +// Associate actions using the `actions!` macro (or `Action` derive macro) actions!(set_menus, [Quit]); // Define the quit function that is registered with the App diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 70e1d1e4cd0b0303bf487848fa308b29d3b69910..de7ba782b2039c00c729343daa92d094b59ad248 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1370,7 +1370,9 @@ impl App { self.keymap.clone() } - /// Register a global listener for actions invoked via the keyboard. + /// Register a global handler for actions invoked via the keyboard. These handlers are run at + /// the end of the bubble phase for actions, and so will only be invoked if there are no other + /// handlers or if they called `cx.propagate()`. pub fn on_action(&mut self, listener: impl Fn(&A, &mut Self) + 'static) { self.global_action_listeners .entry(TypeId::of::()) diff --git a/crates/migrator/src/migrations/m_2025_04_15/keymap.rs b/crates/migrator/src/migrations/m_2025_04_15/keymap.rs index d1443a922afc52a37912d8aa78b5c9f0d4b4e017..efbdc6b1c64443c4733c73568a13a70cc3fa1f97 100644 --- a/crates/migrator/src/migrations/m_2025_04_15/keymap.rs +++ b/crates/migrator/src/migrations/m_2025_04_15/keymap.rs @@ -25,7 +25,7 @@ fn replace_string_action( None } -/// "ctrl-k ctrl-1": "inline_completion::ToggleMenu" -> "edit_prediction::ToggleMenu" +/// "space": "outline_panel::Open" -> "outline_panel::OpenSelectedEntry" static STRING_REPLACE: LazyLock> = LazyLock::new(|| { HashMap::from_iter([("outline_panel::Open", "outline_panel::OpenSelectedEntry")]) }); diff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rs index b2a13b54b662f106018667de9635a4c896e1993c..bed25d0c054fc4e1767cc852597db13dc2cb434c 100644 --- a/crates/theme/src/schema.rs +++ b/crates/theme/src/schema.rs @@ -4,11 +4,10 @@ use anyhow::Result; use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance}; use indexmap::IndexMap; use palette::FromColor; -use schemars::{JsonSchema, json_schema}; +use schemars::{JsonSchema, JsonSchema_repr}; use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; use serde_repr::{Deserialize_repr, Serialize_repr}; -use std::borrow::Cow; use crate::{StatusColorsRefinement, ThemeColorsRefinement}; @@ -1486,7 +1485,7 @@ impl From for FontStyle { } } -#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq)] +#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, JsonSchema_repr, PartialEq)] #[repr(u16)] pub enum FontWeightContent { Thin = 100, @@ -1500,19 +1499,6 @@ pub enum FontWeightContent { Black = 900, } -impl JsonSchema for FontWeightContent { - fn schema_name() -> Cow<'static, str> { - "FontWeightContent".into() - } - - fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema { - json_schema!({ - "type": "integer", - "enum": [100, 200, 300, 400, 500, 600, 700, 800, 900] - }) - } -} - impl From for FontWeight { fn from(value: FontWeightContent) -> Self { match value { diff --git a/crates/util/src/schemars.rs b/crates/util/src/schemars.rs index 4d8ab530dd6beb3cf3c448256ff4bde89f9de8f7..e162b41933117eb603d36601aaf4b87b0e3d1d85 100644 --- a/crates/util/src/schemars.rs +++ b/crates/util/src/schemars.rs @@ -15,7 +15,6 @@ pub fn replace_subschema( generator: &mut schemars::SchemaGenerator, schema: impl Fn() -> schemars::Schema, ) -> schemars::Schema { - // fallback on just using the schema name, which could collide. let schema_name = T::schema_name(); let definitions = generator.definitions_mut(); assert!(!definitions.contains_key(&format!("{schema_name}2")));