mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
Add command_palette_hooks
crate (#8398)
This PR introduces a new `command_palette_hooks` crate that contains the types used to hook into the behavior of the command palette. The `CommandPaletteFilter` was previously extracted to the `copilot` crate in #7095, solely because that was the earliest ancestor of the crates that depended on it. The `CommandPaletteInterceptor` was still defined in `command_palette` itself. Both of these types were consumed by other crates wanting to influence the behavior of the command palette, but required taking a dependency on the entire `command_palette` crate in order to gain access to these hooks. By moving them out into their own crate, we can improve the compile order and make crates like `vim` able to begin building sooner without having to wait for `command_palette` to finish compiling. Here's a comparison of the compilation graph before and after (ignore the timings): #### Before <img width="332" alt="Screenshot 2024-02-25 at 12 42 29 PM" src="https://github.com/zed-industries/zed/assets/1486634/a57c662e-fbc2-41ab-9e30-cca17afa6c73"> #### After <img width="362" alt="Screenshot 2024-02-25 at 12 51 15 PM" src="https://github.com/zed-industries/zed/assets/1486634/c1a6d29c-b607-4604-8f1b-e5d318bf8849"> Release Notes: - N/A
This commit is contained in:
parent
b29946130e
commit
6ef32374d6
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -2214,7 +2214,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"client",
|
"client",
|
||||||
"collections",
|
"collections",
|
||||||
"copilot",
|
"command_palette_hooks",
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
@ -2237,6 +2237,14 @@ dependencies = [
|
|||||||
"zed_actions",
|
"zed_actions",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "command_palette_hooks"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"collections",
|
||||||
|
"gpui",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@ -2296,6 +2304,7 @@ dependencies = [
|
|||||||
"async-tar",
|
"async-tar",
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
|
"command_palette_hooks",
|
||||||
"fs",
|
"fs",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
@ -11002,7 +11011,7 @@ dependencies = [
|
|||||||
"async-trait",
|
"async-trait",
|
||||||
"collections",
|
"collections",
|
||||||
"command_palette",
|
"command_palette",
|
||||||
"copilot",
|
"command_palette_hooks",
|
||||||
"editor",
|
"editor",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
@ -16,6 +16,7 @@ members = [
|
|||||||
"crates/collab_ui",
|
"crates/collab_ui",
|
||||||
"crates/collections",
|
"crates/collections",
|
||||||
"crates/command_palette",
|
"crates/command_palette",
|
||||||
|
"crates/command_palette_hooks",
|
||||||
"crates/copilot",
|
"crates/copilot",
|
||||||
"crates/copilot_ui",
|
"crates/copilot_ui",
|
||||||
"crates/db",
|
"crates/db",
|
||||||
@ -111,6 +112,7 @@ collab_ui = { path = "crates/collab_ui" }
|
|||||||
collections = { path = "crates/collections" }
|
collections = { path = "crates/collections" }
|
||||||
color = { path = "crates/color" }
|
color = { path = "crates/color" }
|
||||||
command_palette = { path = "crates/command_palette" }
|
command_palette = { path = "crates/command_palette" }
|
||||||
|
command_palette_hooks = { path = "crates/command_palette_hooks" }
|
||||||
copilot = { path = "crates/copilot" }
|
copilot = { path = "crates/copilot" }
|
||||||
copilot_ui = { path = "crates/copilot_ui" }
|
copilot_ui = { path = "crates/copilot_ui" }
|
||||||
db = { path = "crates/db" }
|
db = { path = "crates/db" }
|
||||||
|
@ -13,11 +13,11 @@ doctest = false
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
client.workspace = true
|
client.workspace = true
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
# HACK: We're only depending on `copilot` here for `CommandPaletteFilter`. See the attached comment on that type.
|
command_palette_hooks.workspace = true
|
||||||
copilot.workspace = true
|
|
||||||
fuzzy.workspace = true
|
fuzzy.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
picker.workspace = true
|
picker.workspace = true
|
||||||
|
postage.workspace = true
|
||||||
project.workspace = true
|
project.workspace = true
|
||||||
release_channel.workspace = true
|
release_channel.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
@ -27,7 +27,6 @@ ui.workspace = true
|
|||||||
util.workspace = true
|
util.workspace = true
|
||||||
workspace.workspace = true
|
workspace.workspace = true
|
||||||
zed_actions.workspace = true
|
zed_actions.workspace = true
|
||||||
postage.workspace = true
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ctor.workspace = true
|
ctor.workspace = true
|
||||||
|
@ -6,7 +6,9 @@ use std::{
|
|||||||
|
|
||||||
use client::telemetry::Telemetry;
|
use client::telemetry::Telemetry;
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use copilot::CommandPaletteFilter;
|
use command_palette_hooks::{
|
||||||
|
CommandInterceptResult, CommandPaletteFilter, CommandPaletteInterceptor,
|
||||||
|
};
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, Action, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Global,
|
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 {
|
pub struct CommandPaletteDelegate {
|
||||||
command_palette: WeakView<CommandPalette>,
|
command_palette: WeakView<CommandPalette>,
|
||||||
all_commands: Vec<Command>,
|
all_commands: Vec<Command>,
|
||||||
|
14
crates/command_palette_hooks/Cargo.toml
Normal file
14
crates/command_palette_hooks/Cargo.toml
Normal file
@ -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
|
1
crates/command_palette_hooks/LICENSE-GPL
Symbolic link
1
crates/command_palette_hooks/LICENSE-GPL
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../LICENSE-GPL
|
24
crates/command_palette_hooks/src/command_palette_hooks.rs
Normal file
24
crates/command_palette_hooks/src/command_palette_hooks.rs
Normal file
@ -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>,
|
||||||
|
}
|
@ -24,6 +24,7 @@ anyhow.workspace = true
|
|||||||
async-compression.workspace = true
|
async-compression.workspace = true
|
||||||
async-tar.workspace = true
|
async-tar.workspace = true
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
|
command_palette_hooks.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
|
@ -3,6 +3,7 @@ use anyhow::{anyhow, Context as _, Result};
|
|||||||
use async_compression::futures::bufread::GzipDecoder;
|
use async_compression::futures::bufread::GzipDecoder;
|
||||||
use async_tar::Archive;
|
use async_tar::Archive;
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
|
use command_palette_hooks::CommandPaletteFilter;
|
||||||
use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt};
|
use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Global, Model,
|
actions, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Global, Model,
|
||||||
@ -32,17 +33,6 @@ use util::{
|
|||||||
ResultExt,
|
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!(
|
actions!(
|
||||||
copilot,
|
copilot,
|
||||||
[
|
[
|
||||||
|
@ -17,9 +17,7 @@ anyhow.workspace = true
|
|||||||
async-compat = { version = "0.2.1", "optional" = true }
|
async-compat = { version = "0.2.1", "optional" = true }
|
||||||
async-trait = { workspace = true, "optional" = true }
|
async-trait = { workspace = true, "optional" = true }
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
command_palette.workspace = true
|
command_palette_hooks.workspace = true
|
||||||
# HACK: We're only depending on `copilot` here for `CommandPaletteFilter`. See the attached comment on that type.
|
|
||||||
copilot.workspace = true
|
|
||||||
editor.workspace = true
|
editor.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
@ -41,6 +39,7 @@ zed_actions.workspace = true
|
|||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
command_palette.workspace = true
|
||||||
editor = { workspace = true, features = ["test-support"] }
|
editor = { workspace = true, features = ["test-support"] }
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
gpui = { workspace = true, features = ["test-support"] }
|
gpui = { workspace = true, features = ["test-support"] }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use command_palette::CommandInterceptResult;
|
use command_palette_hooks::CommandInterceptResult;
|
||||||
use editor::actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
|
use editor::actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
|
||||||
use gpui::{impl_actions, Action, AppContext, ViewContext};
|
use gpui::{impl_actions, Action, AppContext, ViewContext};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
|
@ -16,8 +16,7 @@ mod visual;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use command_palette::CommandPaletteInterceptor;
|
use command_palette_hooks::{CommandPaletteFilter, CommandPaletteInterceptor};
|
||||||
use copilot::CommandPaletteFilter;
|
|
||||||
use editor::{movement, Editor, EditorEvent, EditorMode};
|
use editor::{movement, Editor, EditorEvent, EditorMode};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, impl_actions, Action, AppContext, EntityId, Global, Subscription, View, ViewContext,
|
actions, impl_actions, Action, AppContext, EntityId, Global, Subscription, View, ViewContext,
|
||||||
|
Loading…
Reference in New Issue
Block a user