Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/hover/tests.rs')
-rw-r--r--crates/ide/src/hover/tests.rs193
1 files changed, 174 insertions, 19 deletions
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 2e7637e467..014b751f95 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -23,7 +23,7 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
max_subst_ty_len: super::SubstTyLen::Unlimited,
};
-fn check_hover_no_result(ra_fixture: &str) {
+fn check_hover_no_result(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -35,7 +35,7 @@ fn check_hover_no_result(ra_fixture: &str) {
}
#[track_caller]
-fn check(ra_fixture: &str, expect: Expect) {
+fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -55,7 +55,7 @@ fn check(ra_fixture: &str, expect: Expect) {
#[track_caller]
fn check_hover_fields_limit(
fields_count: impl Into<Option<usize>>,
- ra_fixture: &str,
+ #[rust_analyzer::rust_fixture] ra_fixture: &str,
expect: Expect,
) {
let (analysis, position) = fixture::position(ra_fixture);
@@ -81,7 +81,7 @@ fn check_hover_fields_limit(
#[track_caller]
fn check_hover_enum_variants_limit(
variants_count: impl Into<Option<usize>>,
- ra_fixture: &str,
+ #[rust_analyzer::rust_fixture] ra_fixture: &str,
expect: Expect,
) {
let (analysis, position) = fixture::position(ra_fixture);
@@ -105,7 +105,11 @@ fn check_hover_enum_variants_limit(
}
#[track_caller]
-fn check_assoc_count(count: usize, ra_fixture: &str, expect: Expect) {
+fn check_assoc_count(
+ count: usize,
+ #[rust_analyzer::rust_fixture] ra_fixture: &str,
+ expect: Expect,
+) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -126,7 +130,7 @@ fn check_assoc_count(count: usize, ra_fixture: &str, expect: Expect) {
expect.assert_eq(&actual)
}
-fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
+fn check_hover_no_links(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -143,7 +147,7 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
expect.assert_eq(&actual)
}
-fn check_hover_no_memory_layout(ra_fixture: &str, expect: Expect) {
+fn check_hover_no_memory_layout(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -160,7 +164,7 @@ fn check_hover_no_memory_layout(ra_fixture: &str, expect: Expect) {
expect.assert_eq(&actual)
}
-fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
+fn check_hover_no_markdown(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
.hover(
@@ -181,7 +185,7 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
expect.assert_eq(&actual)
}
-fn check_actions(ra_fixture: &str, expect: Expect) {
+fn check_actions(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
let mut hover = analysis
.hover(
@@ -206,13 +210,13 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
expect.assert_debug_eq(&hover.info.actions)
}
-fn check_hover_range(ra_fixture: &str, expect: Expect) {
+fn check_hover_range(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, range) = fixture::range(ra_fixture);
let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap().unwrap();
expect.assert_eq(hover.info.markup.as_str())
}
-fn check_hover_range_actions(ra_fixture: &str, expect: Expect) {
+fn check_hover_range_actions(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (analysis, range) = fixture::range(ra_fixture);
let mut hover = analysis
.hover(&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG }, range)
@@ -234,7 +238,7 @@ fn check_hover_range_actions(ra_fixture: &str, expect: Expect) {
expect.assert_debug_eq(&hover.info.actions);
}
-fn check_hover_range_no_results(ra_fixture: &str) {
+fn check_hover_range_no_results(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
let (analysis, range) = fixture::range(ra_fixture);
let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap();
assert!(hover.is_none());
@@ -2365,6 +2369,97 @@ fn test() {
}
#[test]
+fn test_hover_show_type_def_for_func_param() {
+ check_actions(
+ r#"
+struct Bar;
+fn f(b: Bar) {
+
+}
+
+fn test() {
+ let b = Bar;
+ f$0(b);
+}
+"#,
+ expect![[r#"
+ [
+ Reference(
+ FilePositionWrapper {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 15,
+ },
+ ),
+ GoToType(
+ [
+ HoverGotoTypeData {
+ mod_path: "ra_test_fixture::Bar",
+ nav: NavigationTarget {
+ file_id: FileId(
+ 0,
+ ),
+ full_range: 0..11,
+ focus_range: 7..10,
+ name: "Bar",
+ kind: Struct,
+ description: "struct Bar",
+ },
+ },
+ ],
+ ),
+ ]
+ "#]],
+ );
+}
+
+#[test]
+fn test_hover_show_type_def_for_trait_bound() {
+ check_actions(
+ r#"
+trait Bar {}
+fn f<T: Bar>(b: T) {
+
+}
+
+fn test() {
+ f$0();
+}
+"#,
+ expect![[r#"
+ [
+ Reference(
+ FilePositionWrapper {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 16,
+ },
+ ),
+ GoToType(
+ [
+ HoverGotoTypeData {
+ mod_path: "ra_test_fixture::Bar",
+ nav: NavigationTarget {
+ file_id: FileId(
+ 0,
+ ),
+ full_range: 0..12,
+ focus_range: 6..9,
+ name: "Bar",
+ kind: Trait,
+ description: "trait Bar",
+ },
+ },
+ ],
+ ),
+ ]
+ "#]],
+ );
+}
+
+#[test]
fn test_hover_non_ascii_space_doc() {
check(
"
@@ -4700,6 +4795,10 @@ fn hover_lifetime() {
*'lifetime*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
'lifetime
```
"#]],
@@ -4730,6 +4829,10 @@ impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
*T*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
T: TraitA + TraitB
```
"#]],
@@ -4744,6 +4847,10 @@ impl<T> Foo<T$0> {}
*T*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
T
```
"#]],
@@ -4758,6 +4865,10 @@ impl<T: 'static> Foo<T$0> {}
*T*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
T: 'static
```
"#]],
@@ -4778,6 +4889,10 @@ impl<T$0: Trait> Foo<T> {}
*T*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
T: Trait
```
"#]],
@@ -4793,6 +4908,10 @@ impl<T$0: Trait + ?Sized> Foo<T> {}
*T*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
T: Trait + ?Sized
```
"#]],
@@ -4813,6 +4932,10 @@ fn foo<T$0>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T
```
@@ -4834,6 +4957,10 @@ fn foo<T$0: Sized>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T
```
@@ -4855,6 +4982,10 @@ fn foo<T$0: ?Sized>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T: ?Sized
```
@@ -4877,6 +5008,10 @@ fn foo<T$0: Trait>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T: Trait
```
@@ -4899,6 +5034,10 @@ fn foo<T$0: Trait + Sized>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T: Trait
```
@@ -4921,6 +5060,10 @@ fn foo<T$0: Trait + ?Sized>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T: Trait + ?Sized
```
@@ -4942,6 +5085,10 @@ fn foo<T$0: ?Sized + Sized + Sized>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T
```
@@ -4964,6 +5111,10 @@ fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
*T*
```rust
+ ra_test_fixture::foo
+ ```
+
+ ```rust
T: Trait
```
@@ -5011,6 +5162,10 @@ impl<const LEN: usize> Foo<LEN$0> {}
*LEN*
```rust
+ ra_test_fixture::Foo
+ ```
+
+ ```rust
const LEN: usize
```
"#]],
@@ -6112,7 +6267,7 @@ use foo::bar::{self$0};
```
```rust
- mod bar
+ pub mod bar
```
---
@@ -7857,7 +8012,7 @@ fn test() {
*foo*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::S
```
```rust
@@ -7886,7 +8041,7 @@ fn test() {
*foo*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::S
```
```rust
@@ -7916,7 +8071,7 @@ mod m {
*foo*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::inner::S
```
```rust
@@ -7946,7 +8101,7 @@ fn test() {
*A*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::S
```
```rust
@@ -7975,7 +8130,7 @@ fn test() {
*A*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::S
```
```rust
@@ -8005,7 +8160,7 @@ mod m {
*A*
```rust
- ra_test_fixture::S
+ ra_test_fixture::m::inner::S
```
```rust