Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

component: Replace `linkme` with `inventory` (#30705)

Marshall Bowers607bfd3b1c75
diff --git a/Cargo.lock b/Cargo.lock
index 0b8299c94e3..a6b3bc96e7b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -674,7 +674,6 @@ dependencies = [
"language",
"language_model",
"language_models",
- "linkme",
"log",
"markdown",
"open",
@@ -3177,7 +3176,7 @@ version = "0.1.0"
dependencies = [
"collections",
"gpui",
- "linkme",
+ "inventory",
"parking_lot",
"strum 0.27.1",
"theme",
@@ -4327,7 +4326,6 @@ dependencies = [
"gpui",
"indoc",
"language",
- "linkme",
"log",
"lsp",
"markdown",
@@ -6026,7 +6024,6 @@ dependencies = [
"language",
"language_model",
"linkify",
- "linkme",
"log",
"markdown",
"menu",
@@ -9105,7 +9102,6 @@ dependencies = [
"component",
"db",
"gpui",
- "linkme",
"rpc",
"settings",
"sum_tree",
@@ -15707,7 +15703,6 @@ dependencies = [
"component",
"editor",
"gpui",
- "linkme",
"settings",
"theme",
"ui",
@@ -16940,7 +16935,6 @@ dependencies = [
"gpui",
"install_cli",
"language",
- "linkme",
"picker",
"project",
"schemars",
diff --git a/Cargo.toml b/Cargo.toml
index 8d0c97cc029..bb06ba3339e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -795,7 +795,6 @@ ignored = [
"prost_build",
"serde",
"component",
- "linkme",
"documented",
"workspace-hack",
]
diff --git a/crates/assistant_tools/Cargo.toml b/crates/assistant_tools/Cargo.toml
index 5f57d530c0f..3bf249c174e 100644
--- a/crates/assistant_tools/Cargo.toml
+++ b/crates/assistant_tools/Cargo.toml
@@ -35,7 +35,6 @@ indoc.workspace = true
itertools.workspace = true
language.workspace = true
language_model.workspace = true
-linkme.workspace = true
log.workspace = true
markdown.workspace = true
open.workspace = true
diff --git a/crates/component/Cargo.toml b/crates/component/Cargo.toml
index 9591773fcb8..92249de454d 100644
--- a/crates/component/Cargo.toml
+++ b/crates/component/Cargo.toml
@@ -14,7 +14,7 @@ path = "src/component.rs"
[dependencies]
collections.workspace = true
gpui.workspace = true
-linkme.workspace = true
+inventory.workspace = true
parking_lot.workspace = true
strum.workspace = true
theme.workspace = true
diff --git a/crates/component/src/component.rs b/crates/component/src/component.rs
index ebab5d2cde7..00ccab19e6b 100644
--- a/crates/component/src/component.rs
+++ b/crates/component/src/component.rs
@@ -9,13 +9,12 @@
mod component_layout;
-pub use component_layout::*;
-
use std::sync::LazyLock;
+pub use component_layout::*;
+
use collections::HashMap;
use gpui::{AnyElement, App, SharedString, Window};
-use linkme::distributed_slice;
use parking_lot::RwLock;
use strum::{Display, EnumString};
@@ -24,12 +23,27 @@ pub fn components() -> ComponentRegistry {
}
pub fn init() {
- let component_fns: Vec<_> = __ALL_COMPONENTS.iter().cloned().collect();
- for f in component_fns {
- f();
+ for f in inventory::iter::<ComponentFn>() {
+ (f.0)();
+ }
+}
+
+pub struct ComponentFn(fn());
+
+impl ComponentFn {
+ pub const fn new(f: fn()) -> Self {
+ Self(f)
}
}
+inventory::collect!(ComponentFn);
+
+/// Private internals for macros.
+#[doc(hidden)]
+pub mod __private {
+ pub use inventory;
+}
+
pub fn register_component<T: Component>() {
let id = T::id();
let metadata = ComponentMetadata {
@@ -46,9 +60,6 @@ pub fn register_component<T: Component>() {
data.components.insert(id, metadata);
}
-#[distributed_slice]
-pub static __ALL_COMPONENTS: [fn()] = [..];
-
pub static COMPONENT_DATA: LazyLock<RwLock<ComponentRegistry>> =
LazyLock::new(|| RwLock::new(ComponentRegistry::default()));
diff --git a/crates/diagnostics/Cargo.toml b/crates/diagnostics/Cargo.toml
index 5d781a5c180..1b1e880498e 100644
--- a/crates/diagnostics/Cargo.toml
+++ b/crates/diagnostics/Cargo.toml
@@ -23,7 +23,6 @@ futures.workspace = true
gpui.workspace = true
indoc.workspace = true
language.workspace = true
-linkme.workspace = true
log.workspace = true
lsp.workspace = true
markdown.workspace = true
diff --git a/crates/git_ui/Cargo.toml b/crates/git_ui/Cargo.toml
index c391ba9e0ca..33f5a4e4fd1 100644
--- a/crates/git_ui/Cargo.toml
+++ b/crates/git_ui/Cargo.toml
@@ -35,7 +35,6 @@ itertools.workspace = true
language.workspace = true
language_model.workspace = true
linkify.workspace = true
-linkme.workspace = true
log.workspace = true
markdown.workspace = true
menu.workspace = true
diff --git a/crates/notifications/Cargo.toml b/crates/notifications/Cargo.toml
index fb420aef9ac..7c2be845d71 100644
--- a/crates/notifications/Cargo.toml
+++ b/crates/notifications/Cargo.toml
@@ -28,7 +28,6 @@ collections.workspace = true
component.workspace = true
db.workspace = true
gpui.workspace = true
-linkme.workspace = true
rpc.workspace = true
sum_tree.workspace = true
time.workspace = true
diff --git a/crates/ui_input/Cargo.toml b/crates/ui_input/Cargo.toml
index 38c7a09393d..0f337597f0f 100644
--- a/crates/ui_input/Cargo.toml
+++ b/crates/ui_input/Cargo.toml
@@ -15,7 +15,6 @@ path = "src/ui_input.rs"
component.workspace = true
editor.workspace = true
gpui.workspace = true
-linkme.workspace = true
settings.workspace = true
theme.workspace = true
ui.workspace = true
diff --git a/crates/ui_macros/src/derive_register_component.rs b/crates/ui_macros/src/derive_register_component.rs
index 38f6c5018fc..27248e2aacd 100644
--- a/crates/ui_macros/src/derive_register_component.rs
+++ b/crates/ui_macros/src/derive_register_component.rs
@@ -5,7 +5,7 @@ use syn::{DeriveInput, parse_macro_input};
pub fn derive_register_component(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;
- let reg_fn_name = syn::Ident::new(
+ let register_fn_name = syn::Ident::new(
&format!("__component_registry_internal_register_{}", name),
name.span(),
);
@@ -16,10 +16,13 @@ pub fn derive_register_component(input: TokenStream) -> TokenStream {
};
#[allow(non_snake_case)]
- #[linkme::distributed_slice(component::__ALL_COMPONENTS)]
- fn #reg_fn_name() {
+ fn #register_fn_name() {
component::register_component::<#name>();
}
+
+ component::__private::inventory::submit! {
+ component::ComponentFn::new(#register_fn_name)
+ }
};
expanded.into()
}
diff --git a/crates/welcome/Cargo.toml b/crates/welcome/Cargo.toml
index 78a1bb11d12..6d4896016c7 100644
--- a/crates/welcome/Cargo.toml
+++ b/crates/welcome/Cargo.toml
@@ -24,7 +24,6 @@ fuzzy.workspace = true
gpui.workspace = true
install_cli.workspace = true
language.workspace = true
-linkme.workspace = true
picker.workspace = true
project.workspace = true
schemars.workspace = true