From 2b2318e695e85d64c6a976a810620c77b7ccba6e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 7 Dec 2020 17:16:50 +0100 Subject: Remove dummy ProcMacroClient in favor of Option --- crates/proc_macro_api/src/lib.rs | 73 +++++++++++++++------------------------- 1 file changed, 28 insertions(+), 45 deletions(-) (limited to 'crates/proc_macro_api/src/lib.rs') diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index bf1f90879..0d061fd53 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -57,15 +57,10 @@ impl tt::TokenExpander for ProcMacroProcessExpander { } } -#[derive(Debug)] -enum ProcMacroClientKind { - Process { process: Arc, thread: ProcMacroProcessThread }, - Dummy, -} - #[derive(Debug)] pub struct ProcMacroClient { - kind: ProcMacroClientKind, + process: Arc, + thread: ProcMacroProcessThread, } impl ProcMacroClient { @@ -74,47 +69,35 @@ impl ProcMacroClient { args: impl IntoIterator>, ) -> io::Result { let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; - Ok(ProcMacroClient { - kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, - }) - } - - pub fn dummy() -> ProcMacroClient { - ProcMacroClient { kind: ProcMacroClientKind::Dummy } + Ok(ProcMacroClient { process: Arc::new(process), thread }) } pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec { - match &self.kind { - ProcMacroClientKind::Dummy => vec![], - ProcMacroClientKind::Process { process, .. } => { - let macros = match process.find_proc_macros(dylib_path) { - Err(err) => { - eprintln!("Failed to find proc macros. Error: {:#?}", err); - return vec![]; - } - Ok(macros) => macros, - }; - - macros - .into_iter() - .map(|(name, kind)| { - let name = SmolStr::new(&name); - let kind = match kind { - ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, - ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, - ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, - }; - let expander: Arc = - Arc::new(ProcMacroProcessExpander { - process: process.clone(), - name: name.clone(), - dylib_path: dylib_path.into(), - }); - - ProcMacro { name, kind, expander } - }) - .collect() + let macros = match self.process.find_proc_macros(dylib_path) { + Err(err) => { + eprintln!("Failed to find proc macros. Error: {:#?}", err); + return vec![]; } - } + Ok(macros) => macros, + }; + + macros + .into_iter() + .map(|(name, kind)| { + let name = SmolStr::new(&name); + let kind = match kind { + ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, + ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, + ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, + }; + let expander: Arc = Arc::new(ProcMacroProcessExpander { + process: self.process.clone(), + name: name.clone(), + dylib_path: dylib_path.into(), + }); + + ProcMacro { name, kind, expander } + }) + .collect() } } -- cgit v1.2.3