Merge #7152
7152: Implement hover for ConstParam r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
dcb5387b42
3 changed files with 41 additions and 15 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>
|
||||
where
|
||||
T: NameOwner + VisibilityOwner,
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl HoverConfig {
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum HoverAction {
|
||||
Runnable(Runnable),
|
||||
Implementaion(FilePosition),
|
||||
Implementation(FilePosition),
|
||||
GoToType(Vec<HoverGotoTypeData>),
|
||||
}
|
||||
|
||||
|
|
@ -116,12 +116,13 @@ pub(crate) fn hover(
|
|||
};
|
||||
if let Some(definition) = definition {
|
||||
if let Some(markup) = hover_for_definition(db, definition) {
|
||||
let markup = markup.as_str();
|
||||
let markup = if !markdown {
|
||||
remove_markdown(&markup.as_str())
|
||||
remove_markdown(markup)
|
||||
} else if links_in_hover {
|
||||
rewrite_links(db, &markup.as_str(), &definition)
|
||||
rewrite_links(db, markup, &definition)
|
||||
} else {
|
||||
remove_links(&markup.as_str())
|
||||
remove_links(markup)
|
||||
};
|
||||
res.markup = Markup::from(markup);
|
||||
if let Some(action) = show_implementations_action(db, definition) {
|
||||
|
|
@ -175,7 +176,7 @@ pub(crate) fn hover(
|
|||
|
||||
fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
|
||||
fn to_action(nav_target: NavigationTarget) -> HoverAction {
|
||||
HoverAction::Implementaion(FilePosition {
|
||||
HoverAction::Implementation(FilePosition {
|
||||
file_id: nav_target.file_id,
|
||||
offset: nav_target.focus_or_full_range().start(),
|
||||
})
|
||||
|
|
@ -371,10 +372,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
|
|||
Definition::Label(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::ConstParam(_) => {
|
||||
// FIXME: Hover for generic const param
|
||||
None
|
||||
}
|
||||
Definition::ConstParam(it) => from_def_source(db, it, None),
|
||||
};
|
||||
|
||||
fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
|
||||
|
|
@ -1394,7 +1392,7 @@ fn bar() { fo<|>o(); }
|
|||
r"unsafe trait foo<|>() {}",
|
||||
expect![[r#"
|
||||
[
|
||||
Implementaion(
|
||||
Implementation(
|
||||
FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
|
|
@ -2106,7 +2104,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
|
|||
r#"trait foo<|>() {}"#,
|
||||
expect![[r#"
|
||||
[
|
||||
Implementaion(
|
||||
Implementation(
|
||||
FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
|
|
@ -2125,7 +2123,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
|
|||
r"struct foo<|>() {}",
|
||||
expect![[r#"
|
||||
[
|
||||
Implementaion(
|
||||
Implementation(
|
||||
FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
|
|
@ -2144,7 +2142,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
|
|||
r#"union foo<|>() {}"#,
|
||||
expect![[r#"
|
||||
[
|
||||
Implementaion(
|
||||
Implementation(
|
||||
FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
|
|
@ -2163,7 +2161,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
|
|||
r"enum foo<|>() { A, B }",
|
||||
expect![[r#"
|
||||
[
|
||||
Implementaion(
|
||||
Implementation(
|
||||
FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
|
|
@ -3305,4 +3303,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
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1648,7 +1648,7 @@ fn prepare_hover_actions(
|
|||
actions
|
||||
.iter()
|
||||
.filter_map(|it| match it {
|
||||
HoverAction::Implementaion(position) => show_impl_command_link(snap, position),
|
||||
HoverAction::Implementation(position) => show_impl_command_link(snap, position),
|
||||
HoverAction::Runnable(r) => runnable_action_links(snap, file_id, r.clone()),
|
||||
HoverAction::GoToType(targets) => goto_type_action_links(snap, targets),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue