diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/runnables.rs | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index faa91541e..27d35de5b 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -2,7 +2,7 @@ use std::fmt; | |||
2 | 2 | ||
3 | use ast::NameOwner; | 3 | use ast::NameOwner; |
4 | use cfg::CfgExpr; | 4 | use cfg::CfgExpr; |
5 | use hir::{AsAssocItem, HasAttrs, HasSource, Semantics}; | 5 | use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics}; |
6 | use ide_assists::utils::test_related_attribute; | 6 | use ide_assists::utils::test_related_attribute; |
7 | use ide_db::{ | 7 | use ide_db::{ |
8 | base_db::{FilePosition, FileRange}, | 8 | base_db::{FilePosition, FileRange}, |
@@ -340,11 +340,21 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op | |||
340 | // FIXME: this also looks very wrong | 340 | // FIXME: this also looks very wrong |
341 | if let Some(assoc_def) = assoc_def { | 341 | if let Some(assoc_def) = assoc_def { |
342 | if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) { | 342 | if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) { |
343 | if let Some(adt) = imp.target_ty(sema.db).as_adt() { | 343 | let ty = imp.target_ty(sema.db); |
344 | let name = adt.name(sema.db).to_string(); | 344 | if let Some(adt) = ty.as_adt() { |
345 | let name = adt.name(sema.db); | ||
345 | let idx = path.rfind(':').map_or(0, |idx| idx + 1); | 346 | let idx = path.rfind(':').map_or(0, |idx| idx + 1); |
346 | let (prefix, suffix) = path.split_at(idx); | 347 | let (prefix, suffix) = path.split_at(idx); |
347 | return format!("{}{}::{}", prefix, name, suffix); | 348 | let mut ty_params = ty.type_parameters().peekable(); |
349 | let params = if ty_params.peek().is_some() { | ||
350 | format!( | ||
351 | "<{}>", | ||
352 | ty_params.format_with(", ", |ty, cb| cb(&ty.display(sema.db))) | ||
353 | ) | ||
354 | } else { | ||
355 | String::new() | ||
356 | }; | ||
357 | return format!("{}{}{}::{}", prefix, name, params, suffix); | ||
348 | } | 358 | } |
349 | } | 359 | } |
350 | } | 360 | } |
@@ -1406,4 +1416,41 @@ mod tests { | |||
1406 | "#]], | 1416 | "#]], |
1407 | ); | 1417 | ); |
1408 | } | 1418 | } |
1419 | |||
1420 | #[test] | ||
1421 | fn doc_test_type_params() { | ||
1422 | check( | ||
1423 | r#" | ||
1424 | //- /lib.rs | ||
1425 | $0 | ||
1426 | struct Foo<T, U>; | ||
1427 | |||
1428 | impl<T, U> Foo<T, U> { | ||
1429 | /// ```rust | ||
1430 | /// ```` | ||
1431 | fn t() {} | ||
1432 | } | ||
1433 | "#, | ||
1434 | &[&DOCTEST], | ||
1435 | expect![[r#" | ||
1436 | [ | ||
1437 | Runnable { | ||
1438 | nav: NavigationTarget { | ||
1439 | file_id: FileId( | ||
1440 | 0, | ||
1441 | ), | ||
1442 | full_range: 47..85, | ||
1443 | name: "t", | ||
1444 | }, | ||
1445 | kind: DocTest { | ||
1446 | test_id: Path( | ||
1447 | "Foo<T, U>::t", | ||
1448 | ), | ||
1449 | }, | ||
1450 | cfg: None, | ||
1451 | }, | ||
1452 | ] | ||
1453 | "#]], | ||
1454 | ); | ||
1455 | } | ||
1409 | } | 1456 | } |