Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions crates/ide/src/runnables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,13 @@ pub(crate) fn runnable_impl(
let adt_name = ty.as_adt()?.name(sema.db);
let mut ty_args = ty.type_arguments().peekable();
let params = if ty_args.peek().is_some() {
format!("<{}>", ty_args.format_with(", ", |ty, cb| cb(&ty.display(sema.db))))
format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty.display(sema.db))))
} else {
String::new()
};
let test_id = TestId::Path(format!("{}{}", adt_name, params));
let mut test_id = format!("{}{}", adt_name, params);
test_id.retain(|c| c != ' ');
let test_id = TestId::Path(test_id);

Some(Runnable { use_name_in_title: false, nav, kind: RunnableKind::DocTest { test_id }, cfg })
}
Expand Down Expand Up @@ -441,10 +443,11 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
format_to!(
path,
"<{}>",
ty_args.format_with(", ", |ty, cb| cb(&ty.display(db)))
ty_args.format_with(",", |ty, cb| cb(&ty.display(db)))
);
}
format_to!(path, "::{}", def_name);
path.retain(|c| c != ' ');
return Some(path);
}
}
Expand Down Expand Up @@ -2067,13 +2070,23 @@ mod tests {
$0
struct Foo<T, U>;

/// ```
/// ```
impl<T, U> Foo<T, U> {
/// ```rust
/// ````
fn t() {}
}

/// ```
/// ```
impl Foo<Foo<(), ()>, ()> {
/// ```
/// ```
fn t() {}
}
"#,
&[DocTest],
&[DocTest, DocTest, DocTest, DocTest],
expect![[r#"
[
Runnable {
Expand All @@ -2082,12 +2095,64 @@ impl<T, U> Foo<T, U> {
file_id: FileId(
0,
),
full_range: 47..85,
full_range: 20..103,
focus_range: 47..56,
name: "impl",
kind: Impl,
},
kind: DocTest {
test_id: Path(
"Foo<T,U>",
),
},
cfg: None,
},
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 63..101,
name: "t",
},
kind: DocTest {
test_id: Path(
"Foo<T,U>::t",
),
},
cfg: None,
},
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 105..188,
focus_range: 126..146,
name: "impl",
kind: Impl,
},
kind: DocTest {
test_id: Path(
"Foo<Foo<(),()>,()>",
),
},
cfg: None,
},
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 153..186,
name: "t",
},
kind: DocTest {
test_id: Path(
"Foo<T, U>::t",
"Foo<Foo<(),()>,()>::t",
),
},
cfg: None,
Expand Down