Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `command_palette_hooks` crate (#8398)
Marshall Bowers6ef32374d62e
diff --git a/Cargo.lock b/Cargo.lockindex 8302169466f..6a9e294f3be 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.tomlindex 4c505ecd8b3..cad3b3c209a 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.tomlindex 9382db1aa58..a3ad8f95ba0 100644--- a/crates/command_palette/Cargo.toml+++ b/crates/command_palette/Cargo.toml@@ -13,11 +13,11 @@ doctest = falseanyhow.workspace = trueclient.workspace = truecollections.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 = truefuzzy.workspace = truegpui.workspace = truepicker.workspace = true+postage.workspace = trueproject.workspace = truerelease_channel.workspace = trueserde.workspace = true@@ -27,7 +27,6 @@ ui.workspace = trueutil.workspace = trueworkspace.workspace = truezed_actions.workspace = true-postage.workspace = true[dev-dependencies]ctor.workspace = truediff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex 98dd3bcf751..66a300a8a77 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<dyn Fn(&str, &AppContext) -> Option<CommandInterceptResult>>,-);--impl Global for CommandPaletteInterceptor {}--pub struct CommandInterceptResult {- pub action: Box<dyn Action>,- pub string: String,- pub positions: Vec<usize>,-}-pub struct CommandPaletteDelegate {command_palette: WeakView<CommandPalette>,all_commands: Vec<Command>,diff --git a/crates/command_palette_hooks/Cargo.toml b/crates/command_palette_hooks/Cargo.tomlnew file mode 100644index 00000000000..8dd8b7bf69b--- /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 = truediff --git a/crates/command_palette_hooks/LICENSE-GPL b/crates/command_palette_hooks/LICENSE-GPLnew file mode 120000index 00000000000..89e542f750c--- /dev/null+++ b/crates/command_palette_hooks/LICENSE-GPL@@ -0,0 +1 @@+../../LICENSE-GPL\ No newline at end of filediff --git a/crates/command_palette_hooks/src/command_palette_hooks.rs b/crates/command_palette_hooks/src/command_palette_hooks.rsnew file mode 100644index 00000000000..a24955a2558--- /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<TypeId>,+}++impl Global for CommandPaletteFilter {}++pub struct CommandPaletteInterceptor(+ pub Box<dyn Fn(&str, &AppContext) -> Option<CommandInterceptResult>>,+);++impl Global for CommandPaletteInterceptor {}++pub struct CommandInterceptResult {+ pub action: Box<dyn Action>,+ pub string: String,+ pub positions: Vec<usize>,+}diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.tomlindex aa3c3fb4d98..61734eed69f 100644--- a/crates/copilot/Cargo.toml+++ b/crates/copilot/Cargo.toml@@ -24,6 +24,7 @@ anyhow.workspace = trueasync-compression.workspace = trueasync-tar.workspace = truecollections.workspace = true+command_palette_hooks.workspace = truefutures.workspace = truegpui.workspace = truelanguage.workspace = truediff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rsindex 39e7465b262..3356b00f52d 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<TypeId>,-}--impl Global for CommandPaletteFilter {}actions!(copilot,[diff --git a/crates/vim/Cargo.toml b/crates/vim/Cargo.tomlindex 8ae510c8ad4..1ba11f6c849 100644--- a/crates/vim/Cargo.toml+++ b/crates/vim/Cargo.toml@@ -17,9 +17,7 @@ anyhow.workspace = trueasync-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 = trueeditor.workspace = truegpui.workspace = truelanguage.workspace = true@@ -41,6 +39,7 @@ zed_actions.workspace = trueschemars.workspace = true[dev-dependencies]+command_palette.workspace = trueeditor = { workspace = true, features = ["test-support"] }futures.workspace = truegpui = { workspace = true, features = ["test-support"] }diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rsindex d60964041f0..c49aec2c10a 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.rsindex d6cb6c056eb..41f6ed67d22 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,