2022-12-03 12:03:52 +08:00
|
|
|
use flowy_ast::EventEnumAttrs;
|
2022-12-04 15:23:24 +08:00
|
|
|
use quote::format_ident;
|
2021-07-07 14:14:37 +08:00
|
|
|
|
2023-01-31 08:28:31 +08:00
|
|
|
#[allow(dead_code)]
|
2021-07-07 14:14:37 +08:00
|
|
|
pub struct EventASTContext {
|
|
|
|
pub event: syn::Ident,
|
|
|
|
pub event_ty: syn::Ident,
|
|
|
|
pub event_request_struct: syn::Ident,
|
|
|
|
pub event_input: Option<syn::Path>,
|
|
|
|
pub event_output: Option<syn::Path>,
|
2021-07-12 13:53:32 +08:00
|
|
|
pub event_error: String,
|
2021-07-07 14:14:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EventASTContext {
|
2023-01-31 08:28:31 +08:00
|
|
|
#[allow(dead_code)]
|
2022-12-03 12:03:52 +08:00
|
|
|
pub fn from(enum_attrs: &EventEnumAttrs) -> EventASTContext {
|
|
|
|
let command_name = enum_attrs.enum_item_name.clone();
|
2021-07-07 14:14:37 +08:00
|
|
|
if command_name.is_empty() {
|
2022-12-03 12:03:52 +08:00
|
|
|
panic!("Invalid command name: {}", enum_attrs.enum_item_name);
|
2021-07-07 14:14:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let event = format_ident!("{}", &command_name);
|
2021-11-27 19:19:41 +08:00
|
|
|
let splits = command_name.split('_').collect::<Vec<&str>>();
|
2021-07-07 14:14:37 +08:00
|
|
|
|
2022-12-03 12:03:52 +08:00
|
|
|
let event_ty = format_ident!("{}", enum_attrs.enum_name);
|
2021-07-07 14:14:37 +08:00
|
|
|
let event_request_struct = format_ident!("{}Event", &splits.join(""));
|
|
|
|
|
2022-12-03 12:03:52 +08:00
|
|
|
let event_input = enum_attrs.event_input();
|
|
|
|
let event_output = enum_attrs.event_output();
|
|
|
|
let event_error = enum_attrs.event_error();
|
2021-07-07 14:14:37 +08:00
|
|
|
|
|
|
|
EventASTContext {
|
|
|
|
event,
|
|
|
|
event_ty,
|
|
|
|
event_request_struct,
|
|
|
|
event_input,
|
|
|
|
event_output,
|
2021-07-12 13:53:32 +08:00
|
|
|
event_error,
|
2021-07-07 14:14:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|