aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/runnables.rs46
1 files changed, 19 insertions, 27 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index a2a0ad43d..75a2358fa 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -111,21 +111,17 @@ pub(crate) fn runnable(
111 } 111 }
112} 112}
113 113
114fn runnable_fn( 114fn runnable_fn(sema: &Semantics<RootDatabase>, func: ast::Fn, file_id: FileId) -> Option<Runnable> {
115 sema: &Semantics<RootDatabase>, 115 let def = sema.to_def(&func)?;
116 fn_def: ast::Fn, 116 let name_string = func.name()?.text().to_string();
117 file_id: FileId,
118) -> Option<Runnable> {
119 let def = sema.to_def(&fn_def)?;
120 let name_string = fn_def.name()?.text().to_string();
121 117
122 let attrs = def.attrs(sema.db); 118 let attrs = def.attrs(sema.db);
123 let kind = if name_string == "main" { 119 let kind = if name_string == "main" {
124 RunnableKind::Bin 120 RunnableKind::Bin
125 } else { 121 } else {
126 let test_id = match sema.to_def(&fn_def).map(|def| def.module(sema.db)) { 122 let test_id = match sema.to_def(&func).map(|def| def.module(sema.db)) {
127 Some(module) => { 123 Some(module) => {
128 let def = sema.to_def(&fn_def)?; 124 let def = sema.to_def(&func)?;
129 let impl_trait_name = def.as_assoc_item(sema.db).and_then(|assoc_item| { 125 let impl_trait_name = def.as_assoc_item(sema.db).and_then(|assoc_item| {
130 match assoc_item.container(sema.db) { 126 match assoc_item.container(sema.db) {
131 hir::AssocItemContainer::Trait(trait_item) => { 127 hir::AssocItemContainer::Trait(trait_item) => {
@@ -159,10 +155,10 @@ fn runnable_fn(
159 None => TestId::Name(name_string), 155 None => TestId::Name(name_string),
160 }; 156 };
161 157
162 if test_related_attribute(&fn_def).is_some() { 158 if test_related_attribute(&func).is_some() {
163 let attr = TestAttr::from_fn(&fn_def); 159 let attr = TestAttr::from_fn(&func);
164 RunnableKind::Test { test_id, attr } 160 RunnableKind::Test { test_id, attr }
165 } else if fn_def.has_atom_attr("bench") { 161 } else if func.has_atom_attr("bench") {
166 RunnableKind::Bench { test_id } 162 RunnableKind::Bench { test_id }
167 } else if has_runnable_doc_test(&attrs) { 163 } else if has_runnable_doc_test(&attrs) {
168 RunnableKind::DocTest { test_id } 164 RunnableKind::DocTest { test_id }
@@ -171,35 +167,31 @@ fn runnable_fn(
171 } 167 }
172 }; 168 };
173 169
174 let cfg = attrs.cfg();
175
176 let nav = if let RunnableKind::DocTest { .. } = kind { 170 let nav = if let RunnableKind::DocTest { .. } = kind {
177 NavigationTarget::from_doc_commented( 171 NavigationTarget::from_doc_commented(
178 sema.db, 172 sema.db,
179 InFile::new(file_id.into(), &fn_def), 173 InFile::new(file_id.into(), &func),
180 InFile::new(file_id.into(), &fn_def), 174 InFile::new(file_id.into(), &func),
181 ) 175 )
182 } else { 176 } else {
183 NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)) 177 NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &func))
184 }; 178 };
185 Some(Runnable { nav, kind, cfg }) 179 Some(Runnable { nav, kind, cfg: attrs.cfg() })
186} 180}
187 181
188fn runnable_struct( 182fn runnable_struct(
189 sema: &Semantics<RootDatabase>, 183 sema: &Semantics<RootDatabase>,
190 struct_def: ast::Struct, 184 strukt: ast::Struct,
191 file_id: FileId, 185 file_id: FileId,
192) -> Option<Runnable> { 186) -> Option<Runnable> {
193 let def = sema.to_def(&struct_def)?; 187 let def = sema.to_def(&strukt)?;
194 let name_string = struct_def.name()?.text().to_string(); 188 let name_string = strukt.name()?.text().to_string();
195 189
196 let attrs = def.attrs(sema.db); 190 let attrs = def.attrs(sema.db);
197 if !has_runnable_doc_test(&attrs) { 191 if !has_runnable_doc_test(&attrs) {
198 return None; 192 return None;
199 } 193 }
200 let cfg = attrs.cfg(); 194 let test_id = match sema.to_def(&strukt).map(|def| def.module(sema.db)) {
201
202 let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) {
203 Some(module) => { 195 Some(module) => {
204 let path_iter = module 196 let path_iter = module
205 .path_to_root(sema.db) 197 .path_to_root(sema.db)
@@ -216,10 +208,10 @@ fn runnable_struct(
216 208
217 let nav = NavigationTarget::from_doc_commented( 209 let nav = NavigationTarget::from_doc_commented(
218 sema.db, 210 sema.db,
219 InFile::new(file_id.into(), &struct_def), 211 InFile::new(file_id.into(), &strukt),
220 InFile::new(file_id.into(), &struct_def), 212 InFile::new(file_id.into(), &strukt),
221 ); 213 );
222 Some(Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg }) 214 Some(Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg: attrs.cfg() })
223} 215}
224 216
225#[derive(Debug, Copy, Clone)] 217#[derive(Debug, Copy, Clone)]