mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Show type of Self on hover
This commit is contained in:
parent
65a789368a
commit
9349d9ee48
1 changed files with 71 additions and 42 deletions
|
@ -295,7 +295,6 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
|
||||||
ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
|
ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
Definition::SelfType(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
.map(|name| name.to_string())
|
.map(|name| name.to_string())
|
||||||
|
@ -357,7 +356,14 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
|
||||||
ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
|
ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
|
||||||
},
|
},
|
||||||
Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
|
Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
|
||||||
Definition::TypeParam(_) | Definition::SelfType(_) => {
|
Definition::SelfType(impl_def) => {
|
||||||
|
impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
|
||||||
|
Adt::Struct(it) => from_def_source(db, it, mod_path),
|
||||||
|
Adt::Union(it) => from_def_source(db, it, mod_path),
|
||||||
|
Adt::Enum(it) => from_def_source(db, it, mod_path),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Definition::TypeParam(_) => {
|
||||||
// FIXME: Hover for generic param
|
// FIXME: Hover for generic param
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -1025,52 +1031,75 @@ impl Thing {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*Self { x: 0 }*
|
*Self*
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
Thing
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Thing
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
)
|
);
|
||||||
} /* FIXME: revive these tests
|
check(
|
||||||
let (analysis, position) = fixture::position(
|
r#"
|
||||||
"
|
struct Thing { x: u32 }
|
||||||
struct Thing { x: u32 }
|
impl Thing {
|
||||||
impl Thing {
|
fn new() -> Self<|> { Self { x: 0 } }
|
||||||
fn new() -> Self<|> {
|
}
|
||||||
Self { x: 0 }
|
"#,
|
||||||
}
|
expect![[r#"
|
||||||
}
|
*Self*
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
```rust
|
||||||
assert_eq!(trim_markup(&hover.info.markup.as_str()), ("Thing"));
|
test
|
||||||
|
```
|
||||||
|
|
||||||
let (analysis, position) = fixture::position(
|
```rust
|
||||||
"
|
struct Thing
|
||||||
enum Thing { A }
|
```
|
||||||
impl Thing {
|
"#]],
|
||||||
pub fn new() -> Self<|> {
|
);
|
||||||
Thing::A
|
check(
|
||||||
}
|
r#"
|
||||||
}
|
enum Thing { A }
|
||||||
",
|
impl Thing {
|
||||||
);
|
pub fn new() -> Self<|> { Thing::A }
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
}
|
||||||
assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing"));
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*Self*
|
||||||
|
|
||||||
let (analysis, position) = fixture::position(
|
```rust
|
||||||
"
|
test
|
||||||
enum Thing { A }
|
```
|
||||||
impl Thing {
|
|
||||||
pub fn thing(a: Self<|>) {
|
```rust
|
||||||
}
|
enum Thing
|
||||||
}
|
```
|
||||||
",
|
"#]],
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
check(
|
||||||
assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing"));
|
r#"
|
||||||
*/
|
enum Thing { A }
|
||||||
|
impl Thing {
|
||||||
|
pub fn thing(a: Self<|>) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*Self*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
enum Thing
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_shadowing_pat() {
|
fn test_hover_shadowing_pat() {
|
||||||
|
|
Loading…
Reference in a new issue