diff options
author | Lukas Wirth <[email protected]> | 2021-03-17 13:38:11 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-03-17 13:48:57 +0000 |
commit | ec824a92d05caa1908cb25cbd5b969c8e995aaa7 (patch) | |
tree | 4d64f1a745735200fbdbc3df564f1471d1b44be1 /crates/ide/src | |
parent | 0fbfab3b45af7a02b1224bca4a53e9b8f6ec049e (diff) |
Better handling of block doc comments
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/goto_definition.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 34 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 48 |
3 files changed, 83 insertions, 7 deletions
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index b71f4917c..5072ecea0 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -95,12 +95,10 @@ fn extract_positioned_link_from_comment( | |||
95 | let comment_range = comment.syntax().text_range(); | 95 | let comment_range = comment.syntax().text_range(); |
96 | let doc_comment = comment.doc_comment()?; | 96 | let doc_comment = comment.doc_comment()?; |
97 | let def_links = extract_definitions_from_markdown(doc_comment); | 97 | let def_links = extract_definitions_from_markdown(doc_comment); |
98 | let start = comment_range.start() + TextSize::from(comment.prefix().len() as u32); | ||
98 | let (def_link, ns, _) = def_links.iter().min_by_key(|(_, _, def_link_range)| { | 99 | let (def_link, ns, _) = def_links.iter().min_by_key(|(_, _, def_link_range)| { |
99 | let matched_position = comment_range.start() + TextSize::from(def_link_range.start as u32); | 100 | let matched_position = start + TextSize::from(def_link_range.start as u32); |
100 | match position.offset.checked_sub(matched_position) { | 101 | position.offset.checked_sub(matched_position).unwrap_or_else(|| comment_range.end()) |
101 | Some(distance) => distance, | ||
102 | None => comment_range.end(), | ||
103 | } | ||
104 | })?; | 102 | })?; |
105 | Some((def_link.to_string(), *ns)) | 103 | Some((def_link.to_string(), *ns)) |
106 | } | 104 | } |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 325014622..cc2b79124 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -3424,6 +3424,40 @@ mod Foo$0 { | |||
3424 | } | 3424 | } |
3425 | 3425 | ||
3426 | #[test] | 3426 | #[test] |
3427 | fn hover_doc_block_style_indentend() { | ||
3428 | check( | ||
3429 | r#" | ||
3430 | /** | ||
3431 | foo | ||
3432 | ```rust | ||
3433 | let x = 3; | ||
3434 | ``` | ||
3435 | */ | ||
3436 | fn foo$0() {} | ||
3437 | "#, | ||
3438 | expect![[r#" | ||
3439 | *foo* | ||
3440 | |||
3441 | ```rust | ||
3442 | test | ||
3443 | ``` | ||
3444 | |||
3445 | ```rust | ||
3446 | fn foo() | ||
3447 | ``` | ||
3448 | |||
3449 | --- | ||
3450 | |||
3451 | foo | ||
3452 | |||
3453 | ```rust | ||
3454 | let x = 3; | ||
3455 | ``` | ||
3456 | "#]], | ||
3457 | ); | ||
3458 | } | ||
3459 | |||
3460 | #[test] | ||
3427 | fn hover_comments_dont_highlight_parent() { | 3461 | fn hover_comments_dont_highlight_parent() { |
3428 | check_hover_no_result( | 3462 | check_hover_no_result( |
3429 | r#" | 3463 | r#" |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 397e2126b..bea020b06 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -576,6 +576,20 @@ fn should_have_runnable_1() {} | |||
576 | /// ``` | 576 | /// ``` |
577 | fn should_have_runnable_2() {} | 577 | fn should_have_runnable_2() {} |
578 | 578 | ||
579 | /** | ||
580 | ```rust | ||
581 | let z = 55; | ||
582 | ``` | ||
583 | */ | ||
584 | fn should_have_no_runnable_3() {} | ||
585 | |||
586 | /** | ||
587 | ```rust | ||
588 | let z = 55; | ||
589 | ``` | ||
590 | */ | ||
591 | fn should_have_no_runnable_4() {} | ||
592 | |||
579 | /// ```no_run | 593 | /// ```no_run |
580 | /// let z = 55; | 594 | /// let z = 55; |
581 | /// ``` | 595 | /// ``` |
@@ -616,7 +630,7 @@ fn should_have_no_runnable_6() {} | |||
616 | struct StructWithRunnable(String); | 630 | struct StructWithRunnable(String); |
617 | 631 | ||
618 | "#, | 632 | "#, |
619 | &[&BIN, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST], | 633 | &[&BIN, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST], |
620 | expect![[r#" | 634 | expect![[r#" |
621 | [ | 635 | [ |
622 | Runnable { | 636 | Runnable { |
@@ -682,7 +696,37 @@ struct StructWithRunnable(String); | |||
682 | file_id: FileId( | 696 | file_id: FileId( |
683 | 0, | 697 | 0, |
684 | ), | 698 | ), |
685 | full_range: 756..821, | 699 | full_range: 256..320, |
700 | name: "should_have_no_runnable_3", | ||
701 | }, | ||
702 | kind: DocTest { | ||
703 | test_id: Path( | ||
704 | "should_have_no_runnable_3", | ||
705 | ), | ||
706 | }, | ||
707 | cfg: None, | ||
708 | }, | ||
709 | Runnable { | ||
710 | nav: NavigationTarget { | ||
711 | file_id: FileId( | ||
712 | 0, | ||
713 | ), | ||
714 | full_range: 322..398, | ||
715 | name: "should_have_no_runnable_4", | ||
716 | }, | ||
717 | kind: DocTest { | ||
718 | test_id: Path( | ||
719 | "should_have_no_runnable_4", | ||
720 | ), | ||
721 | }, | ||
722 | cfg: None, | ||
723 | }, | ||
724 | Runnable { | ||
725 | nav: NavigationTarget { | ||
726 | file_id: FileId( | ||
727 | 0, | ||
728 | ), | ||
729 | full_range: 900..965, | ||
686 | name: "StructWithRunnable", | 730 | name: "StructWithRunnable", |
687 | }, | 731 | }, |
688 | kind: DocTest { | 732 | kind: DocTest { |