mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Implement hover for ConstParam
This commit is contained in:
parent
5771cad451
commit
0ae0909a16
2 changed files with 29 additions and 4 deletions
|
@ -87,6 +87,17 @@ impl ShortLabel for ast::Variant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ShortLabel for ast::ConstParam {
|
||||||
|
fn short_label(&self) -> Option<String> {
|
||||||
|
let mut buf = "const ".to_owned();
|
||||||
|
buf.push_str(self.name()?.text().as_str());
|
||||||
|
if let Some(type_ref) = self.ty() {
|
||||||
|
format_to!(buf, ": {}", type_ref.syntax());
|
||||||
|
}
|
||||||
|
Some(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String>
|
fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String>
|
||||||
where
|
where
|
||||||
T: NameOwner + VisibilityOwner,
|
T: NameOwner + VisibilityOwner,
|
||||||
|
|
|
@ -371,10 +371,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
|
||||||
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
|
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
|
||||||
Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
|
Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
|
||||||
Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
|
Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
|
||||||
Definition::ConstParam(_) => {
|
Definition::ConstParam(it) => from_def_source(db, it, None),
|
||||||
// FIXME: Hover for generic const param
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
|
fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
|
||||||
|
@ -3305,4 +3302,21 @@ impl<T: 'static> Foo<T<|>> {}
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hover_const_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Foo<const LEN: usize>;
|
||||||
|
impl<const LEN: usize> Foo<LEN<|>> {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*LEN*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const LEN: usize
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue