diff options
-rw-r--r-- | crates/ide/src/display/short_label.rs | 11 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 43 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 2 |
3 files changed, 41 insertions, 15 deletions
diff --git a/crates/ide/src/display/short_label.rs b/crates/ide/src/display/short_label.rs index ea49d9f97..990f740b8 100644 --- a/crates/ide/src/display/short_label.rs +++ b/crates/ide/src/display/short_label.rs | |||
@@ -87,6 +87,17 @@ impl ShortLabel for ast::Variant { | |||
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | impl ShortLabel for ast::ConstParam { | ||
91 | fn short_label(&self) -> Option<String> { | ||
92 | let mut buf = "const ".to_owned(); | ||
93 | buf.push_str(self.name()?.text().as_str()); | ||
94 | if let Some(type_ref) = self.ty() { | ||
95 | format_to!(buf, ": {}", type_ref.syntax()); | ||
96 | } | ||
97 | Some(buf) | ||
98 | } | ||
99 | } | ||
100 | |||
90 | fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String> | 101 | fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String> |
91 | where | 102 | where |
92 | T: NameOwner + VisibilityOwner, | 103 | T: NameOwner + VisibilityOwner, |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 61439ae53..c0786eb51 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -70,7 +70,7 @@ impl HoverConfig { | |||
70 | #[derive(Debug, Clone)] | 70 | #[derive(Debug, Clone)] |
71 | pub enum HoverAction { | 71 | pub enum HoverAction { |
72 | Runnable(Runnable), | 72 | Runnable(Runnable), |
73 | Implementaion(FilePosition), | 73 | Implementation(FilePosition), |
74 | GoToType(Vec<HoverGotoTypeData>), | 74 | GoToType(Vec<HoverGotoTypeData>), |
75 | } | 75 | } |
76 | 76 | ||
@@ -116,12 +116,13 @@ pub(crate) fn hover( | |||
116 | }; | 116 | }; |
117 | if let Some(definition) = definition { | 117 | if let Some(definition) = definition { |
118 | if let Some(markup) = hover_for_definition(db, definition) { | 118 | if let Some(markup) = hover_for_definition(db, definition) { |
119 | let markup = markup.as_str(); | ||
119 | let markup = if !markdown { | 120 | let markup = if !markdown { |
120 | remove_markdown(&markup.as_str()) | 121 | remove_markdown(markup) |
121 | } else if links_in_hover { | 122 | } else if links_in_hover { |
122 | rewrite_links(db, &markup.as_str(), &definition) | 123 | rewrite_links(db, markup, &definition) |
123 | } else { | 124 | } else { |
124 | remove_links(&markup.as_str()) | 125 | remove_links(markup) |
125 | }; | 126 | }; |
126 | res.markup = Markup::from(markup); | 127 | res.markup = Markup::from(markup); |
127 | if let Some(action) = show_implementations_action(db, definition) { | 128 | if let Some(action) = show_implementations_action(db, definition) { |
@@ -175,7 +176,7 @@ pub(crate) fn hover( | |||
175 | 176 | ||
176 | fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> { | 177 | fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> { |
177 | fn to_action(nav_target: NavigationTarget) -> HoverAction { | 178 | fn to_action(nav_target: NavigationTarget) -> HoverAction { |
178 | HoverAction::Implementaion(FilePosition { | 179 | HoverAction::Implementation(FilePosition { |
179 | file_id: nav_target.file_id, | 180 | file_id: nav_target.file_id, |
180 | offset: nav_target.focus_or_full_range().start(), | 181 | offset: nav_target.focus_or_full_range().start(), |
181 | }) | 182 | }) |
@@ -371,10 +372,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> { | |||
371 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), | 372 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), |
372 | Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), | 373 | Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), |
373 | Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), | 374 | Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), |
374 | Definition::ConstParam(_) => { | 375 | Definition::ConstParam(it) => from_def_source(db, it, None), |
375 | // FIXME: Hover for generic const param | ||
376 | None | ||
377 | } | ||
378 | }; | 376 | }; |
379 | 377 | ||
380 | fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> | 378 | fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> |
@@ -1394,7 +1392,7 @@ fn bar() { fo<|>o(); } | |||
1394 | r"unsafe trait foo<|>() {}", | 1392 | r"unsafe trait foo<|>() {}", |
1395 | expect![[r#" | 1393 | expect![[r#" |
1396 | [ | 1394 | [ |
1397 | Implementaion( | 1395 | Implementation( |
1398 | FilePosition { | 1396 | FilePosition { |
1399 | file_id: FileId( | 1397 | file_id: FileId( |
1400 | 0, | 1398 | 0, |
@@ -2106,7 +2104,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2106 | r#"trait foo<|>() {}"#, | 2104 | r#"trait foo<|>() {}"#, |
2107 | expect![[r#" | 2105 | expect![[r#" |
2108 | [ | 2106 | [ |
2109 | Implementaion( | 2107 | Implementation( |
2110 | FilePosition { | 2108 | FilePosition { |
2111 | file_id: FileId( | 2109 | file_id: FileId( |
2112 | 0, | 2110 | 0, |
@@ -2125,7 +2123,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2125 | r"struct foo<|>() {}", | 2123 | r"struct foo<|>() {}", |
2126 | expect![[r#" | 2124 | expect![[r#" |
2127 | [ | 2125 | [ |
2128 | Implementaion( | 2126 | Implementation( |
2129 | FilePosition { | 2127 | FilePosition { |
2130 | file_id: FileId( | 2128 | file_id: FileId( |
2131 | 0, | 2129 | 0, |
@@ -2144,7 +2142,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2144 | r#"union foo<|>() {}"#, | 2142 | r#"union foo<|>() {}"#, |
2145 | expect![[r#" | 2143 | expect![[r#" |
2146 | [ | 2144 | [ |
2147 | Implementaion( | 2145 | Implementation( |
2148 | FilePosition { | 2146 | FilePosition { |
2149 | file_id: FileId( | 2147 | file_id: FileId( |
2150 | 0, | 2148 | 0, |
@@ -2163,7 +2161,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } | |||
2163 | r"enum foo<|>() { A, B }", | 2161 | r"enum foo<|>() { A, B }", |
2164 | expect![[r#" | 2162 | expect![[r#" |
2165 | [ | 2163 | [ |
2166 | Implementaion( | 2164 | Implementation( |
2167 | FilePosition { | 2165 | FilePosition { |
2168 | file_id: FileId( | 2166 | file_id: FileId( |
2169 | 0, | 2167 | 0, |
@@ -3305,4 +3303,21 @@ impl<T: 'static> Foo<T<|>> {} | |||
3305 | "#]], | 3303 | "#]], |
3306 | ); | 3304 | ); |
3307 | } | 3305 | } |
3306 | |||
3307 | #[test] | ||
3308 | fn hover_const_param() { | ||
3309 | check( | ||
3310 | r#" | ||
3311 | struct Foo<const LEN: usize>; | ||
3312 | impl<const LEN: usize> Foo<LEN<|>> {} | ||
3313 | "#, | ||
3314 | expect![[r#" | ||
3315 | *LEN* | ||
3316 | |||
3317 | ```rust | ||
3318 | const LEN: usize | ||
3319 | ``` | ||
3320 | "#]], | ||
3321 | ); | ||
3322 | } | ||
3308 | } | 3323 | } |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index dd486070b..c21ca044a 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -1648,7 +1648,7 @@ fn prepare_hover_actions( | |||
1648 | actions | 1648 | actions |
1649 | .iter() | 1649 | .iter() |
1650 | .filter_map(|it| match it { | 1650 | .filter_map(|it| match it { |
1651 | HoverAction::Implementaion(position) => show_impl_command_link(snap, position), | 1651 | HoverAction::Implementation(position) => show_impl_command_link(snap, position), |
1652 | HoverAction::Runnable(r) => runnable_action_links(snap, file_id, r.clone()), | 1652 | HoverAction::Runnable(r) => runnable_action_links(snap, file_id, r.clone()), |
1653 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), | 1653 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), |
1654 | }) | 1654 | }) |