diff options
author | Jonas Schievink <[email protected]> | 2020-12-07 16:16:50 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-07 16:16:50 +0000 |
commit | 2b2318e695e85d64c6a976a810620c77b7ccba6e (patch) | |
tree | 2ec1166251fd2791cbd77372dbae29aa51522a3f /crates/proc_macro_api/src | |
parent | fb21a215be0968d1102aba842c0fdedcd401cb15 (diff) |
Remove dummy ProcMacroClient in favor of Option
Diffstat (limited to 'crates/proc_macro_api/src')
-rw-r--r-- | crates/proc_macro_api/src/lib.rs | 73 |
1 files changed, 28 insertions, 45 deletions
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 | |||
@@ -58,14 +58,9 @@ impl tt::TokenExpander for ProcMacroProcessExpander { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | #[derive(Debug)] | 60 | #[derive(Debug)] |
61 | enum ProcMacroClientKind { | ||
62 | Process { process: Arc<ProcMacroProcessSrv>, thread: ProcMacroProcessThread }, | ||
63 | Dummy, | ||
64 | } | ||
65 | |||
66 | #[derive(Debug)] | ||
67 | pub struct ProcMacroClient { | 61 | pub struct ProcMacroClient { |
68 | kind: ProcMacroClientKind, | 62 | process: Arc<ProcMacroProcessSrv>, |
63 | thread: ProcMacroProcessThread, | ||
69 | } | 64 | } |
70 | 65 | ||
71 | impl ProcMacroClient { | 66 | impl ProcMacroClient { |
@@ -74,47 +69,35 @@ impl ProcMacroClient { | |||
74 | args: impl IntoIterator<Item = impl AsRef<OsStr>>, | 69 | args: impl IntoIterator<Item = impl AsRef<OsStr>>, |
75 | ) -> io::Result<ProcMacroClient> { | 70 | ) -> io::Result<ProcMacroClient> { |
76 | let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; | 71 | let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; |
77 | Ok(ProcMacroClient { | 72 | Ok(ProcMacroClient { process: Arc::new(process), thread }) |
78 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, | ||
79 | }) | ||
80 | } | ||
81 | |||
82 | pub fn dummy() -> ProcMacroClient { | ||
83 | ProcMacroClient { kind: ProcMacroClientKind::Dummy } | ||
84 | } | 73 | } |
85 | 74 | ||
86 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { | 75 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { |
87 | match &self.kind { | 76 | let macros = match self.process.find_proc_macros(dylib_path) { |
88 | ProcMacroClientKind::Dummy => vec![], | 77 | Err(err) => { |
89 | ProcMacroClientKind::Process { process, .. } => { | 78 | eprintln!("Failed to find proc macros. Error: {:#?}", err); |
90 | let macros = match process.find_proc_macros(dylib_path) { | 79 | return vec![]; |
91 | Err(err) => { | ||
92 | eprintln!("Failed to find proc macros. Error: {:#?}", err); | ||
93 | return vec![]; | ||
94 | } | ||
95 | Ok(macros) => macros, | ||
96 | }; | ||
97 | |||
98 | macros | ||
99 | .into_iter() | ||
100 | .map(|(name, kind)| { | ||
101 | let name = SmolStr::new(&name); | ||
102 | let kind = match kind { | ||
103 | ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, | ||
104 | ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, | ||
105 | ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, | ||
106 | }; | ||
107 | let expander: Arc<dyn tt::TokenExpander> = | ||
108 | Arc::new(ProcMacroProcessExpander { | ||
109 | process: process.clone(), | ||
110 | name: name.clone(), | ||
111 | dylib_path: dylib_path.into(), | ||
112 | }); | ||
113 | |||
114 | ProcMacro { name, kind, expander } | ||
115 | }) | ||
116 | .collect() | ||
117 | } | 80 | } |
118 | } | 81 | Ok(macros) => macros, |
82 | }; | ||
83 | |||
84 | macros | ||
85 | .into_iter() | ||
86 | .map(|(name, kind)| { | ||
87 | let name = SmolStr::new(&name); | ||
88 | let kind = match kind { | ||
89 | ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, | ||
90 | ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, | ||
91 | ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, | ||
92 | }; | ||
93 | let expander: Arc<dyn tt::TokenExpander> = Arc::new(ProcMacroProcessExpander { | ||
94 | process: self.process.clone(), | ||
95 | name: name.clone(), | ||
96 | dylib_path: dylib_path.into(), | ||
97 | }); | ||
98 | |||
99 | ProcMacro { name, kind, expander } | ||
100 | }) | ||
101 | .collect() | ||
119 | } | 102 | } |
120 | } | 103 | } |