Better handling of block doc comments

This commit is contained in:
Lukas Wirth 2021-03-17 14:38:11 +01:00
parent 0fbfab3b45
commit ec824a92d0
8 changed files with 158 additions and 81 deletions

View file

@ -95,12 +95,10 @@ fn extract_positioned_link_from_comment(
let comment_range = comment.syntax().text_range();
let doc_comment = comment.doc_comment()?;
let def_links = extract_definitions_from_markdown(doc_comment);
let start = comment_range.start() + TextSize::from(comment.prefix().len() as u32);
let (def_link, ns, _) = def_links.iter().min_by_key(|(_, _, def_link_range)| {
let matched_position = comment_range.start() + TextSize::from(def_link_range.start as u32);
match position.offset.checked_sub(matched_position) {
Some(distance) => distance,
None => comment_range.end(),
}
let matched_position = start + TextSize::from(def_link_range.start as u32);
position.offset.checked_sub(matched_position).unwrap_or_else(|| comment_range.end())
})?;
Some((def_link.to_string(), *ns))
}

View file

@ -3423,6 +3423,40 @@ mod Foo$0 {
);
}
#[test]
fn hover_doc_block_style_indentend() {
check(
r#"
/**
foo
```rust
let x = 3;
```
*/
fn foo$0() {}
"#,
expect![[r#"
*foo*
```rust
test
```
```rust
fn foo()
```
---
foo
```rust
let x = 3;
```
"#]],
);
}
#[test]
fn hover_comments_dont_highlight_parent() {
check_hover_no_result(

View file

@ -576,6 +576,20 @@ fn should_have_runnable_1() {}
/// ```
fn should_have_runnable_2() {}
/**
```rust
let z = 55;
```
*/
fn should_have_no_runnable_3() {}
/**
```rust
let z = 55;
```
*/
fn should_have_no_runnable_4() {}
/// ```no_run
/// let z = 55;
/// ```
@ -616,7 +630,7 @@ fn should_have_no_runnable_6() {}
struct StructWithRunnable(String);
"#,
&[&BIN, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST],
&[&BIN, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST],
expect![[r#"
[
Runnable {
@ -682,7 +696,37 @@ struct StructWithRunnable(String);
file_id: FileId(
0,
),
full_range: 756..821,
full_range: 256..320,
name: "should_have_no_runnable_3",
},
kind: DocTest {
test_id: Path(
"should_have_no_runnable_3",
),
},
cfg: None,
},
Runnable {
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 322..398,
name: "should_have_no_runnable_4",
},
kind: DocTest {
test_id: Path(
"should_have_no_runnable_4",
),
},
cfg: None,
},
Runnable {
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 900..965,
name: "StructWithRunnable",
},
kind: DocTest {