diff options
author | Lukas Wirth <[email protected]> | 2021-01-04 13:18:31 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-01-04 13:18:31 +0000 |
commit | 0ae0909a1676903baf33999d5f23d51fb838111b (patch) | |
tree | 53c456c75f3d136dc2b63c64bf20a012e0d0efc8 /crates | |
parent | 5771cad4517005afe134d0b9c93571c177f14db4 (diff) |
Implement hover for ConstParam
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/display/short_label.rs | 11 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 22 |
2 files changed, 29 insertions, 4 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..e9103ce59 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -371,10 +371,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> { | |||
371 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), | 371 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), |
372 | Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), | 372 | Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), |
373 | Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), | 373 | Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), |
374 | Definition::ConstParam(_) => { | 374 | Definition::ConstParam(it) => from_def_source(db, it, None), |
375 | // FIXME: Hover for generic const param | ||
376 | None | ||
377 | } | ||
378 | }; | 375 | }; |
379 | 376 | ||
380 | fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> | 377 | 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<|>> {} | |||
3305 | "#]], | 3302 | "#]], |
3306 | ); | 3303 | ); |
3307 | } | 3304 | } |
3305 | |||
3306 | #[test] | ||
3307 | fn hover_const_param() { | ||
3308 | check( | ||
3309 | r#" | ||
3310 | struct Foo<const LEN: usize>; | ||
3311 | impl<const LEN: usize> Foo<LEN<|>> {} | ||
3312 | "#, | ||
3313 | expect![[r#" | ||
3314 | *LEN* | ||
3315 | |||
3316 | ```rust | ||
3317 | const LEN: usize | ||
3318 | ``` | ||
3319 | "#]], | ||
3320 | ); | ||
3321 | } | ||
3308 | } | 3322 | } |