diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index a460370c5..a96c5f157 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -10,13 +10,14 @@ use ra_syntax::{ | |||
10 | 10 | ||
11 | use crate::FileId; | 11 | use crate::FileId; |
12 | use ast::DocCommentsOwner; | 12 | use ast::DocCommentsOwner; |
13 | use ra_cfg::CfgExpr; | ||
13 | use std::fmt::Display; | 14 | use std::fmt::Display; |
14 | 15 | ||
15 | #[derive(Debug)] | 16 | #[derive(Debug)] |
16 | pub struct Runnable { | 17 | pub struct Runnable { |
17 | pub range: TextRange, | 18 | pub range: TextRange, |
18 | pub kind: RunnableKind, | 19 | pub kind: RunnableKind, |
19 | pub features_needed: Option<Vec<SmolStr>>, | 20 | pub cfg_exprs: Vec<CfgExpr>, |
20 | } | 21 | } |
21 | 22 | ||
22 | #[derive(Debug)] | 23 | #[derive(Debug)] |
@@ -118,9 +119,10 @@ fn runnable_fn( | |||
118 | }; | 119 | }; |
119 | 120 | ||
120 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); | 121 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); |
121 | let features_needed = get_features_needed(attrs); | 122 | let cfg_exprs = |
123 | attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)).collect(); | ||
122 | 124 | ||
123 | Some(Runnable { range: fn_def.syntax().text_range(), kind, features_needed }) | 125 | Some(Runnable { range: fn_def.syntax().text_range(), kind, cfg_exprs }) |
124 | } | 126 | } |
125 | 127 | ||
126 | #[derive(Debug)] | 128 | #[derive(Debug)] |
@@ -183,15 +185,10 @@ fn runnable_mod( | |||
183 | .join("::"); | 185 | .join("::"); |
184 | 186 | ||
185 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module)); | 187 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module)); |
186 | let features_needed = get_features_needed(attrs); | 188 | let cfg_exprs = |
189 | attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)).collect(); | ||
187 | 190 | ||
188 | Some(Runnable { range, kind: RunnableKind::TestMod { path }, features_needed }) | 191 | Some(Runnable { range, kind: RunnableKind::TestMod { path }, cfg_exprs }) |
189 | } | ||
190 | |||
191 | fn get_features_needed(attrs: Attrs) -> Option<Vec<SmolStr>> { | ||
192 | let cfg_expr = attrs.by_key("cfg").tt_values().map(|subtree| ra_cfg::parse_cfg(subtree)); | ||
193 | let features_needed = cfg_expr.map(|cfg| cfg.minimal_features_needed()).flatten().collect(); | ||
194 | Some(features_needed).filter(|it: &Vec<SmolStr>| !it.is_empty()) | ||
195 | } | 192 | } |
196 | 193 | ||
197 | #[cfg(test)] | 194 | #[cfg(test)] |
@@ -223,7 +220,7 @@ mod tests { | |||
223 | Runnable { | 220 | Runnable { |
224 | range: 1..21, | 221 | range: 1..21, |
225 | kind: Bin, | 222 | kind: Bin, |
226 | features_needed: None, | 223 | cfg_exprs: [], |
227 | }, | 224 | }, |
228 | Runnable { | 225 | Runnable { |
229 | range: 22..46, | 226 | range: 22..46, |
@@ -235,7 +232,7 @@ mod tests { | |||
235 | ignore: false, | 232 | ignore: false, |
236 | }, | 233 | }, |
237 | }, | 234 | }, |
238 | features_needed: None, | 235 | cfg_exprs: [], |
239 | }, | 236 | }, |
240 | Runnable { | 237 | Runnable { |
241 | range: 47..81, | 238 | range: 47..81, |
@@ -247,7 +244,7 @@ mod tests { | |||
247 | ignore: true, | 244 | ignore: true, |
248 | }, | 245 | }, |
249 | }, | 246 | }, |
250 | features_needed: None, | 247 | cfg_exprs: [], |
251 | }, | 248 | }, |
252 | ] | 249 | ] |
253 | "### | 250 | "### |
@@ -275,7 +272,7 @@ mod tests { | |||
275 | Runnable { | 272 | Runnable { |
276 | range: 1..21, | 273 | range: 1..21, |
277 | kind: Bin, | 274 | kind: Bin, |
278 | features_needed: None, | 275 | cfg_exprs: [], |
279 | }, | 276 | }, |
280 | Runnable { | 277 | Runnable { |
281 | range: 22..64, | 278 | range: 22..64, |
@@ -284,7 +281,7 @@ mod tests { | |||
284 | "foo", | 281 | "foo", |
285 | ), | 282 | ), |
286 | }, | 283 | }, |
287 | features_needed: None, | 284 | cfg_exprs: [], |
288 | }, | 285 | }, |
289 | ] | 286 | ] |
290 | "### | 287 | "### |
@@ -315,7 +312,7 @@ mod tests { | |||
315 | Runnable { | 312 | Runnable { |
316 | range: 1..21, | 313 | range: 1..21, |
317 | kind: Bin, | 314 | kind: Bin, |
318 | features_needed: None, | 315 | cfg_exprs: [], |
319 | }, | 316 | }, |
320 | Runnable { | 317 | Runnable { |
321 | range: 51..105, | 318 | range: 51..105, |
@@ -324,7 +321,7 @@ mod tests { | |||
324 | "Data::foo", | 321 | "Data::foo", |
325 | ), | 322 | ), |
326 | }, | 323 | }, |
327 | features_needed: None, | 324 | cfg_exprs: [], |
328 | }, | 325 | }, |
329 | ] | 326 | ] |
330 | "### | 327 | "### |
@@ -352,7 +349,7 @@ mod tests { | |||
352 | kind: TestMod { | 349 | kind: TestMod { |
353 | path: "test_mod", | 350 | path: "test_mod", |
354 | }, | 351 | }, |
355 | features_needed: None, | 352 | cfg_exprs: [], |
356 | }, | 353 | }, |
357 | Runnable { | 354 | Runnable { |
358 | range: 28..57, | 355 | range: 28..57, |
@@ -364,7 +361,7 @@ mod tests { | |||
364 | ignore: false, | 361 | ignore: false, |
365 | }, | 362 | }, |
366 | }, | 363 | }, |
367 | features_needed: None, | 364 | cfg_exprs: [], |
368 | }, | 365 | }, |
369 | ] | 366 | ] |
370 | "### | 367 | "### |
@@ -394,7 +391,7 @@ mod tests { | |||
394 | kind: TestMod { | 391 | kind: TestMod { |
395 | path: "foo::test_mod", | 392 | path: "foo::test_mod", |
396 | }, | 393 | }, |
397 | features_needed: None, | 394 | cfg_exprs: [], |
398 | }, | 395 | }, |
399 | Runnable { | 396 | Runnable { |
400 | range: 46..79, | 397 | range: 46..79, |
@@ -406,7 +403,7 @@ mod tests { | |||
406 | ignore: false, | 403 | ignore: false, |
407 | }, | 404 | }, |
408 | }, | 405 | }, |
409 | features_needed: None, | 406 | cfg_exprs: [], |
410 | }, | 407 | }, |
411 | ] | 408 | ] |
412 | "### | 409 | "### |
@@ -438,7 +435,7 @@ mod tests { | |||
438 | kind: TestMod { | 435 | kind: TestMod { |
439 | path: "foo::bar::test_mod", | 436 | path: "foo::bar::test_mod", |
440 | }, | 437 | }, |
441 | features_needed: None, | 438 | cfg_exprs: [], |
442 | }, | 439 | }, |
443 | Runnable { | 440 | Runnable { |
444 | range: 68..105, | 441 | range: 68..105, |
@@ -450,7 +447,7 @@ mod tests { | |||
450 | ignore: false, | 447 | ignore: false, |
451 | }, | 448 | }, |
452 | }, | 449 | }, |
453 | features_needed: None, | 450 | cfg_exprs: [], |
454 | }, | 451 | }, |
455 | ] | 452 | ] |
456 | "### | 453 | "### |
@@ -482,11 +479,12 @@ mod tests { | |||
482 | ignore: false, | 479 | ignore: false, |
483 | }, | 480 | }, |
484 | }, | 481 | }, |
485 | features_needed: Some( | 482 | cfg_exprs: [ |
486 | [ | 483 | KeyValue { |
487 | "foo", | 484 | key: "feature", |
488 | ], | 485 | value: "foo", |
489 | ), | 486 | }, |
487 | ], | ||
490 | }, | 488 | }, |
491 | ] | 489 | ] |
492 | "### | 490 | "### |
@@ -518,12 +516,20 @@ mod tests { | |||
518 | ignore: false, | 516 | ignore: false, |
519 | }, | 517 | }, |
520 | }, | 518 | }, |
521 | features_needed: Some( | 519 | cfg_exprs: [ |
522 | [ | 520 | All( |
523 | "foo", | 521 | [ |
524 | "bar", | 522 | KeyValue { |
525 | ], | 523 | key: "feature", |
526 | ), | 524 | value: "foo", |
525 | }, | ||
526 | KeyValue { | ||
527 | key: "feature", | ||
528 | value: "bar", | ||
529 | }, | ||
530 | ], | ||
531 | ), | ||
532 | ], | ||
527 | }, | 533 | }, |
528 | ] | 534 | ] |
529 | "### | 535 | "### |