Improve actions macros (#3292)
- `actions!` now uses `#[action]` on each struct to reduce duplication. - The `#[action]` macro now works on unit structs. - Renamed `menu::unused` to `menu::init` and added more explanation in comments. Release Notes: - N/A
This commit is contained in:
commit
ca3341f066
4 changed files with 22 additions and 14 deletions
|
@ -176,8 +176,7 @@ macro_rules! actions {
|
||||||
() => {};
|
() => {};
|
||||||
|
|
||||||
( $name:ident ) => {
|
( $name:ident ) => {
|
||||||
#[gpui::register_action]
|
#[gpui::action]
|
||||||
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
|
||||||
pub struct $name;
|
pub struct $name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,21 @@ pub fn action(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let visibility = input.vis;
|
let visibility = input.vis;
|
||||||
|
|
||||||
let output = match input.data {
|
let output = match input.data {
|
||||||
syn::Data::Struct(ref struct_data) => {
|
syn::Data::Struct(ref struct_data) => match &struct_data.fields {
|
||||||
let fields = &struct_data.fields;
|
syn::Fields::Named(_) | syn::Fields::Unnamed(_) => {
|
||||||
quote! {
|
let fields = &struct_data.fields;
|
||||||
#attributes
|
quote! {
|
||||||
#visibility struct #name #fields
|
#attributes
|
||||||
|
#visibility struct #name #fields
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
syn::Fields::Unit => {
|
||||||
|
quote! {
|
||||||
|
#attributes
|
||||||
|
#visibility struct #name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
syn::Data::Enum(ref enum_data) => {
|
syn::Data::Enum(ref enum_data) => {
|
||||||
let variants = &enum_data.variants;
|
let variants = &enum_data.variants;
|
||||||
quote! {
|
quote! {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
use gpui::actions;
|
use gpui::actions;
|
||||||
|
|
||||||
// todo!(remove this)
|
// If the zed binary doesn't use anything in this crate, it will be optimized away
|
||||||
|
// and the actions won't initialize. So we just provide an empty initialization function
|
||||||
|
// to be called from main.
|
||||||
|
//
|
||||||
|
// These may provide relevant context:
|
||||||
// https://github.com/rust-lang/rust/issues/47384
|
// https://github.com/rust-lang/rust/issues/47384
|
||||||
// https://github.com/mmastrac/rust-ctor/issues/280
|
// https://github.com/mmastrac/rust-ctor/issues/280
|
||||||
pub fn unused() {}
|
pub fn init() {}
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
Cancel,
|
Cancel,
|
||||||
|
|
|
@ -57,10 +57,7 @@ use zed2::{
|
||||||
mod open_listener;
|
mod open_listener;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
//TODO!(figure out what the linker issues are here)
|
menu::init();
|
||||||
// https://github.com/rust-lang/rust/issues/47384
|
|
||||||
// https://github.com/mmastrac/rust-ctor/issues/280
|
|
||||||
menu::unused();
|
|
||||||
let http = http::client();
|
let http = http::client();
|
||||||
init_paths();
|
init_paths();
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue