diff --git a/Cargo.lock b/Cargo.lock index 8302169466..6a9e294f3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2214,7 +2214,7 @@ dependencies = [ "anyhow", "client", "collections", - "copilot", + "command_palette_hooks", "ctor", "editor", "env_logger", @@ -2237,6 +2237,14 @@ dependencies = [ "zed_actions", ] +[[package]] +name = "command_palette_hooks" +version = "0.1.0" +dependencies = [ + "collections", + "gpui", +] + [[package]] name = "concurrent-queue" version = "2.2.0" @@ -2296,6 +2304,7 @@ dependencies = [ "async-tar", "clock", "collections", + "command_palette_hooks", "fs", "futures 0.3.28", "gpui", @@ -11002,7 +11011,7 @@ dependencies = [ "async-trait", "collections", "command_palette", - "copilot", + "command_palette_hooks", "editor", "futures 0.3.28", "gpui", diff --git a/Cargo.toml b/Cargo.toml index 4c505ecd8b..cad3b3c209 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "crates/collab_ui", "crates/collections", "crates/command_palette", + "crates/command_palette_hooks", "crates/copilot", "crates/copilot_ui", "crates/db", @@ -111,6 +112,7 @@ collab_ui = { path = "crates/collab_ui" } collections = { path = "crates/collections" } color = { path = "crates/color" } command_palette = { path = "crates/command_palette" } +command_palette_hooks = { path = "crates/command_palette_hooks" } copilot = { path = "crates/copilot" } copilot_ui = { path = "crates/copilot_ui" } db = { path = "crates/db" } diff --git a/crates/command_palette/Cargo.toml b/crates/command_palette/Cargo.toml index 9382db1aa5..a3ad8f95ba 100644 --- a/crates/command_palette/Cargo.toml +++ b/crates/command_palette/Cargo.toml @@ -13,11 +13,11 @@ doctest = false anyhow.workspace = true client.workspace = true collections.workspace = true -# HACK: We're only depending on `copilot` here for `CommandPaletteFilter`. See the attached comment on that type. -copilot.workspace = true +command_palette_hooks.workspace = true fuzzy.workspace = true gpui.workspace = true picker.workspace = true +postage.workspace = true project.workspace = true release_channel.workspace = true serde.workspace = true @@ -27,7 +27,6 @@ ui.workspace = true util.workspace = true workspace.workspace = true zed_actions.workspace = true -postage.workspace = true [dev-dependencies] ctor.workspace = true diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index 98dd3bcf75..66a300a8a7 100644 --- a/crates/command_palette/src/command_palette.rs +++ b/crates/command_palette/src/command_palette.rs @@ -6,7 +6,9 @@ use std::{ use client::telemetry::Telemetry; use collections::HashMap; -use copilot::CommandPaletteFilter; +use command_palette_hooks::{ + CommandInterceptResult, CommandPaletteFilter, CommandPaletteInterceptor, +}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ actions, Action, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Global, @@ -101,18 +103,6 @@ impl Render for CommandPalette { } } -pub struct CommandPaletteInterceptor( - pub Box Option>, -); - -impl Global for CommandPaletteInterceptor {} - -pub struct CommandInterceptResult { - pub action: Box, - pub string: String, - pub positions: Vec, -} - pub struct CommandPaletteDelegate { command_palette: WeakView, all_commands: Vec, diff --git a/crates/command_palette_hooks/Cargo.toml b/crates/command_palette_hooks/Cargo.toml new file mode 100644 index 0000000000..8dd8b7bf69 --- /dev/null +++ b/crates/command_palette_hooks/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "command_palette_hooks" +version = "0.1.0" +edition = "2021" +publish = false +license = "GPL-3.0-or-later" + +[lib] +path = "src/command_palette_hooks.rs" +doctest = false + +[dependencies] +collections.workspace = true +gpui.workspace = true diff --git a/crates/command_palette_hooks/LICENSE-GPL b/crates/command_palette_hooks/LICENSE-GPL new file mode 120000 index 0000000000..89e542f750 --- /dev/null +++ b/crates/command_palette_hooks/LICENSE-GPL @@ -0,0 +1 @@ +../../LICENSE-GPL \ No newline at end of file diff --git a/crates/command_palette_hooks/src/command_palette_hooks.rs b/crates/command_palette_hooks/src/command_palette_hooks.rs new file mode 100644 index 0000000000..a24955a255 --- /dev/null +++ b/crates/command_palette_hooks/src/command_palette_hooks.rs @@ -0,0 +1,24 @@ +use std::any::TypeId; + +use collections::HashSet; +use gpui::{Action, AppContext, Global}; + +#[derive(Default)] +pub struct CommandPaletteFilter { + pub hidden_namespaces: HashSet<&'static str>, + pub hidden_action_types: HashSet, +} + +impl Global for CommandPaletteFilter {} + +pub struct CommandPaletteInterceptor( + pub Box Option>, +); + +impl Global for CommandPaletteInterceptor {} + +pub struct CommandInterceptResult { + pub action: Box, + pub string: String, + pub positions: Vec, +} diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index aa3c3fb4d9..61734eed69 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -24,6 +24,7 @@ anyhow.workspace = true async-compression.workspace = true async-tar.workspace = true collections.workspace = true +command_palette_hooks.workspace = true futures.workspace = true gpui.workspace = true language.workspace = true diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 39e7465b26..3356b00f52 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -3,6 +3,7 @@ use anyhow::{anyhow, Context as _, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; use collections::{HashMap, HashSet}; +use command_palette_hooks::CommandPaletteFilter; use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt}; use gpui::{ actions, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Global, Model, @@ -32,17 +33,6 @@ use util::{ ResultExt, }; -// HACK: This type is only defined in `copilot` since it is the earliest ancestor -// of the crates that use it. -// -// This is not great. Let's find a better place for it to live. -#[derive(Default)] -pub struct CommandPaletteFilter { - pub hidden_namespaces: HashSet<&'static str>, - pub hidden_action_types: HashSet, -} - -impl Global for CommandPaletteFilter {} actions!( copilot, [ diff --git a/crates/vim/Cargo.toml b/crates/vim/Cargo.toml index 8ae510c8ad..1ba11f6c84 100644 --- a/crates/vim/Cargo.toml +++ b/crates/vim/Cargo.toml @@ -17,9 +17,7 @@ anyhow.workspace = true async-compat = { version = "0.2.1", "optional" = true } async-trait = { workspace = true, "optional" = true } collections.workspace = true -command_palette.workspace = true -# HACK: We're only depending on `copilot` here for `CommandPaletteFilter`. See the attached comment on that type. -copilot.workspace = true +command_palette_hooks.workspace = true editor.workspace = true gpui.workspace = true language.workspace = true @@ -41,6 +39,7 @@ zed_actions.workspace = true schemars.workspace = true [dev-dependencies] +command_palette.workspace = true editor = { workspace = true, features = ["test-support"] } futures.workspace = true gpui = { workspace = true, features = ["test-support"] } diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index d60964041f..c49aec2c10 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -1,4 +1,4 @@ -use command_palette::CommandInterceptResult; +use command_palette_hooks::CommandInterceptResult; use editor::actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive}; use gpui::{impl_actions, Action, AppContext, ViewContext}; use serde_derive::Deserialize; diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index d6cb6c056e..41f6ed67d2 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -16,8 +16,7 @@ mod visual; use anyhow::Result; use collections::HashMap; -use command_palette::CommandPaletteInterceptor; -use copilot::CommandPaletteFilter; +use command_palette_hooks::{CommandPaletteFilter, CommandPaletteInterceptor}; use editor::{movement, Editor, EditorEvent, EditorMode}; use gpui::{ actions, impl_actions, Action, AppContext, EntityId, Global, Subscription, View, ViewContext,