aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_proc_macro_srv/src/dylib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_proc_macro_srv/src/dylib.rs')
-rw-r--r--crates/ra_proc_macro_srv/src/dylib.rs68
1 files changed, 33 insertions, 35 deletions
diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs
index d202eb0fd..476bc5c01 100644
--- a/crates/ra_proc_macro_srv/src/dylib.rs
+++ b/crates/ra_proc_macro_srv/src/dylib.rs
@@ -112,7 +112,7 @@ impl ProcMacroLibraryLibloading {
112type ProcMacroLibraryImpl = ProcMacroLibraryLibloading; 112type ProcMacroLibraryImpl = ProcMacroLibraryLibloading;
113 113
114pub struct Expander { 114pub struct Expander {
115 libs: Vec<ProcMacroLibraryImpl>, 115 inner: ProcMacroLibraryImpl,
116} 116}
117 117
118impl Expander { 118impl Expander {
@@ -125,7 +125,7 @@ impl Expander {
125 125
126 let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?; 126 let library = ProcMacroLibraryImpl::open(&lib).map_err(|e| e.to_string())?;
127 127
128 Ok(Expander { libs: vec![library] }) 128 Ok(Expander { inner: library })
129 } 129 }
130 130
131 pub fn expand( 131 pub fn expand(
@@ -141,38 +141,36 @@ impl Expander {
141 TokenStream::with_subtree(attr.clone()) 141 TokenStream::with_subtree(attr.clone())
142 }); 142 });
143 143
144 for lib in &self.libs { 144 for proc_macro in &self.inner.exported_macros {
145 for proc_macro in &lib.exported_macros { 145 match proc_macro {
146 match proc_macro { 146 bridge::client::ProcMacro::CustomDerive { trait_name, client, .. }
147 bridge::client::ProcMacro::CustomDerive { trait_name, client, .. } 147 if *trait_name == macro_name =>
148 if *trait_name == macro_name => 148 {
149 { 149 let res = client.run(
150 let res = client.run( 150 &crate::proc_macro::bridge::server::SameThread,
151 &crate::proc_macro::bridge::server::SameThread, 151 crate::rustc_server::Rustc::default(),
152 crate::rustc_server::Rustc::default(), 152 parsed_body,
153 parsed_body, 153 );
154 ); 154 return res.map(|it| it.subtree);
155 return res.map(|it| it.subtree); 155 }
156 } 156 bridge::client::ProcMacro::Bang { name, client } if *name == macro_name => {
157 bridge::client::ProcMacro::Bang { name, client } if *name == macro_name => { 157 let res = client.run(
158 let res = client.run( 158 &crate::proc_macro::bridge::server::SameThread,
159 &crate::proc_macro::bridge::server::SameThread, 159 crate::rustc_server::Rustc::default(),
160 crate::rustc_server::Rustc::default(), 160 parsed_body,
161 parsed_body, 161 );
162 ); 162 return res.map(|it| it.subtree);
163 return res.map(|it| it.subtree); 163 }
164 } 164 bridge::client::ProcMacro::Attr { name, client } if *name == macro_name => {
165 bridge::client::ProcMacro::Attr { name, client } if *name == macro_name => { 165 let res = client.run(
166 let res = client.run( 166 &crate::proc_macro::bridge::server::SameThread,
167 &crate::proc_macro::bridge::server::SameThread, 167 crate::rustc_server::Rustc::default(),
168 crate::rustc_server::Rustc::default(), 168 parsed_attributes,
169 parsed_attributes, 169 parsed_body,
170 parsed_body, 170 );
171 ); 171 return res.map(|it| it.subtree);
172 return res.map(|it| it.subtree);
173 }
174 _ => continue,
175 } 172 }
173 _ => continue,
176 } 174 }
177 } 175 }
178 176
@@ -180,9 +178,9 @@ impl Expander {
180 } 178 }
181 179
182 pub fn list_macros(&self) -> Vec<(String, ProcMacroKind)> { 180 pub fn list_macros(&self) -> Vec<(String, ProcMacroKind)> {
183 self.libs 181 self.inner
182 .exported_macros
184 .iter() 183 .iter()
185 .flat_map(|it| &it.exported_macros)
186 .map(|proc_macro| match proc_macro { 184 .map(|proc_macro| match proc_macro {
187 bridge::client::ProcMacro::CustomDerive { trait_name, .. } => { 185 bridge::client::ProcMacro::CustomDerive { trait_name, .. } => {
188 (trait_name.to_string(), ProcMacroKind::CustomDerive) 186 (trait_name.to_string(), ProcMacroKind::CustomDerive)