component: Replace linkme
with inventory
(#30705)
This PR replaces the use of `linkme` with `inventory` for the component preview registration. Release Notes: - N/A
This commit is contained in:
parent
87cb498a41
commit
607bfd3b1c
11 changed files with 28 additions and 27 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -674,7 +674,6 @@ dependencies = [
|
||||||
"language",
|
"language",
|
||||||
"language_model",
|
"language_model",
|
||||||
"language_models",
|
"language_models",
|
||||||
"linkme",
|
|
||||||
"log",
|
"log",
|
||||||
"markdown",
|
"markdown",
|
||||||
"open",
|
"open",
|
||||||
|
@ -3177,7 +3176,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"collections",
|
"collections",
|
||||||
"gpui",
|
"gpui",
|
||||||
"linkme",
|
"inventory",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"strum 0.27.1",
|
"strum 0.27.1",
|
||||||
"theme",
|
"theme",
|
||||||
|
@ -4327,7 +4326,6 @@ dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
"indoc",
|
"indoc",
|
||||||
"language",
|
"language",
|
||||||
"linkme",
|
|
||||||
"log",
|
"log",
|
||||||
"lsp",
|
"lsp",
|
||||||
"markdown",
|
"markdown",
|
||||||
|
@ -6026,7 +6024,6 @@ dependencies = [
|
||||||
"language",
|
"language",
|
||||||
"language_model",
|
"language_model",
|
||||||
"linkify",
|
"linkify",
|
||||||
"linkme",
|
|
||||||
"log",
|
"log",
|
||||||
"markdown",
|
"markdown",
|
||||||
"menu",
|
"menu",
|
||||||
|
@ -9105,7 +9102,6 @@ dependencies = [
|
||||||
"component",
|
"component",
|
||||||
"db",
|
"db",
|
||||||
"gpui",
|
"gpui",
|
||||||
"linkme",
|
|
||||||
"rpc",
|
"rpc",
|
||||||
"settings",
|
"settings",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
|
@ -15707,7 +15703,6 @@ dependencies = [
|
||||||
"component",
|
"component",
|
||||||
"editor",
|
"editor",
|
||||||
"gpui",
|
"gpui",
|
||||||
"linkme",
|
|
||||||
"settings",
|
"settings",
|
||||||
"theme",
|
"theme",
|
||||||
"ui",
|
"ui",
|
||||||
|
@ -16940,7 +16935,6 @@ dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
"install_cli",
|
"install_cli",
|
||||||
"language",
|
"language",
|
||||||
"linkme",
|
|
||||||
"picker",
|
"picker",
|
||||||
"project",
|
"project",
|
||||||
"schemars",
|
"schemars",
|
||||||
|
|
|
@ -795,7 +795,6 @@ ignored = [
|
||||||
"prost_build",
|
"prost_build",
|
||||||
"serde",
|
"serde",
|
||||||
"component",
|
"component",
|
||||||
"linkme",
|
|
||||||
"documented",
|
"documented",
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
]
|
]
|
||||||
|
|
|
@ -35,7 +35,6 @@ indoc.workspace = true
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
language_model.workspace = true
|
language_model.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
markdown.workspace = true
|
markdown.workspace = true
|
||||||
open.workspace = true
|
open.workspace = true
|
||||||
|
|
|
@ -14,7 +14,7 @@ path = "src/component.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
collections.workspace = true
|
collections.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
linkme.workspace = true
|
inventory.workspace = true
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
strum.workspace = true
|
strum.workspace = true
|
||||||
theme.workspace = true
|
theme.workspace = true
|
||||||
|
|
|
@ -9,13 +9,12 @@
|
||||||
|
|
||||||
mod component_layout;
|
mod component_layout;
|
||||||
|
|
||||||
pub use component_layout::*;
|
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
pub use component_layout::*;
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::{AnyElement, App, SharedString, Window};
|
use gpui::{AnyElement, App, SharedString, Window};
|
||||||
use linkme::distributed_slice;
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use strum::{Display, EnumString};
|
use strum::{Display, EnumString};
|
||||||
|
|
||||||
|
@ -24,12 +23,27 @@ pub fn components() -> ComponentRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
let component_fns: Vec<_> = __ALL_COMPONENTS.iter().cloned().collect();
|
for f in inventory::iter::<ComponentFn>() {
|
||||||
for f in component_fns {
|
(f.0)();
|
||||||
f();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>() {
|
pub fn register_component<T: Component>() {
|
||||||
let id = T::id();
|
let id = T::id();
|
||||||
let metadata = ComponentMetadata {
|
let metadata = ComponentMetadata {
|
||||||
|
@ -46,9 +60,6 @@ pub fn register_component<T: Component>() {
|
||||||
data.components.insert(id, metadata);
|
data.components.insert(id, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[distributed_slice]
|
|
||||||
pub static __ALL_COMPONENTS: [fn()] = [..];
|
|
||||||
|
|
||||||
pub static COMPONENT_DATA: LazyLock<RwLock<ComponentRegistry>> =
|
pub static COMPONENT_DATA: LazyLock<RwLock<ComponentRegistry>> =
|
||||||
LazyLock::new(|| RwLock::new(ComponentRegistry::default()));
|
LazyLock::new(|| RwLock::new(ComponentRegistry::default()));
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ futures.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
lsp.workspace = true
|
lsp.workspace = true
|
||||||
markdown.workspace = true
|
markdown.workspace = true
|
||||||
|
|
|
@ -35,7 +35,6 @@ itertools.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
language_model.workspace = true
|
language_model.workspace = true
|
||||||
linkify.workspace = true
|
linkify.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
markdown.workspace = true
|
markdown.workspace = true
|
||||||
menu.workspace = true
|
menu.workspace = true
|
||||||
|
|
|
@ -28,7 +28,6 @@ collections.workspace = true
|
||||||
component.workspace = true
|
component.workspace = true
|
||||||
db.workspace = true
|
db.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
rpc.workspace = true
|
rpc.workspace = true
|
||||||
sum_tree.workspace = true
|
sum_tree.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
|
|
|
@ -15,7 +15,6 @@ path = "src/ui_input.rs"
|
||||||
component.workspace = true
|
component.workspace = true
|
||||||
editor.workspace = true
|
editor.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
theme.workspace = true
|
theme.workspace = true
|
||||||
ui.workspace = true
|
ui.workspace = true
|
||||||
|
|
|
@ -5,7 +5,7 @@ use syn::{DeriveInput, parse_macro_input};
|
||||||
pub fn derive_register_component(input: TokenStream) -> TokenStream {
|
pub fn derive_register_component(input: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(input as DeriveInput);
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
let name = input.ident;
|
let name = input.ident;
|
||||||
let reg_fn_name = syn::Ident::new(
|
let register_fn_name = syn::Ident::new(
|
||||||
&format!("__component_registry_internal_register_{}", name),
|
&format!("__component_registry_internal_register_{}", name),
|
||||||
name.span(),
|
name.span(),
|
||||||
);
|
);
|
||||||
|
@ -16,10 +16,13 @@ pub fn derive_register_component(input: TokenStream) -> TokenStream {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[linkme::distributed_slice(component::__ALL_COMPONENTS)]
|
fn #register_fn_name() {
|
||||||
fn #reg_fn_name() {
|
|
||||||
component::register_component::<#name>();
|
component::register_component::<#name>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component::__private::inventory::submit! {
|
||||||
|
component::ComponentFn::new(#register_fn_name)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
expanded.into()
|
expanded.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ fuzzy.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
install_cli.workspace = true
|
install_cli.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
linkme.workspace = true
|
|
||||||
picker.workspace = true
|
picker.workspace = true
|
||||||
project.workspace = true
|
project.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue