diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-16 15:48:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-16 15:48:35 +0000 |
commit | 00c80b208bcbe52b13bbd03cb62e24b2d2075edf (patch) | |
tree | 7071728ef7945e6fb5a8e527ee6d742e6d8da49e /crates | |
parent | a69f7ce312ba04acbca970a61d9576d520dacb2e (diff) | |
parent | 4d1e1daa31239cb71a81c6958c1b9137274fd189 (diff) |
Merge #8055
8055: Implement HirDisplay for some more types r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/display.rs | 30 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 18 |
2 files changed, 32 insertions, 16 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 44cdcc296..81f0e04e5 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs | |||
@@ -12,8 +12,8 @@ use hir_ty::display::{ | |||
12 | use syntax::ast::{self, NameOwner}; | 12 | use syntax::ast::{self, NameOwner}; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | Const, ConstParam, Enum, Field, Function, HasVisibility, Module, Static, Struct, Substs, Trait, | 15 | Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, |
16 | Type, TypeAlias, TypeParam, Union, Variant, | 16 | Module, Static, Struct, Substs, Trait, Type, TypeAlias, TypeParam, Union, Variant, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | impl HirDisplay for Function { | 19 | impl HirDisplay for Function { |
@@ -120,6 +120,16 @@ impl HirDisplay for Function { | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | impl HirDisplay for Adt { | ||
124 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
125 | match self { | ||
126 | Adt::Struct(it) => it.hir_fmt(f), | ||
127 | Adt::Union(it) => it.hir_fmt(f), | ||
128 | Adt::Enum(it) => it.hir_fmt(f), | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | |||
123 | impl HirDisplay for Struct { | 133 | impl HirDisplay for Struct { |
124 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 134 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
125 | write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; | 135 | write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; |
@@ -211,6 +221,16 @@ impl HirDisplay for Type { | |||
211 | } | 221 | } |
212 | } | 222 | } |
213 | 223 | ||
224 | impl HirDisplay for GenericParam { | ||
225 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
226 | match self { | ||
227 | GenericParam::TypeParam(it) => it.hir_fmt(f), | ||
228 | GenericParam::LifetimeParam(it) => it.hir_fmt(f), | ||
229 | GenericParam::ConstParam(it) => it.hir_fmt(f), | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | |||
214 | impl HirDisplay for TypeParam { | 234 | impl HirDisplay for TypeParam { |
215 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 235 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
216 | write!(f, "{}", self.name(f.db))?; | 236 | write!(f, "{}", self.name(f.db))?; |
@@ -224,6 +244,12 @@ impl HirDisplay for TypeParam { | |||
224 | } | 244 | } |
225 | } | 245 | } |
226 | 246 | ||
247 | impl HirDisplay for LifetimeParam { | ||
248 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
249 | write!(f, "{}", self.name(f.db)) | ||
250 | } | ||
251 | } | ||
252 | |||
227 | impl HirDisplay for ConstParam { | 253 | impl HirDisplay for ConstParam { |
228 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 254 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
229 | write!(f, "const {}: ", self.name(f.db))?; | 255 | write!(f, "const {}: ", self.name(f.db))?; |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 8d45b4875..325014622 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use either::Either; | 1 | use either::Either; |
2 | use hir::{ | 2 | use hir::{ |
3 | Adt, AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module, | 3 | AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module, |
4 | ModuleDef, Semantics, | 4 | ModuleDef, Semantics, |
5 | }; | 5 | }; |
6 | use ide_db::{ | 6 | use ide_db::{ |
@@ -339,9 +339,7 @@ fn hover_for_definition( | |||
339 | Definition::ModuleDef(it) => match it { | 339 | Definition::ModuleDef(it) => match it { |
340 | ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path), | 340 | ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path), |
341 | ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path), | 341 | ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path), |
342 | ModuleDef::Adt(Adt::Struct(it)) => from_hir_fmt(db, it, mod_path), | 342 | ModuleDef::Adt(it) => from_hir_fmt(db, it, mod_path), |
343 | ModuleDef::Adt(Adt::Union(it)) => from_hir_fmt(db, it, mod_path), | ||
344 | ModuleDef::Adt(Adt::Enum(it)) => from_hir_fmt(db, it, mod_path), | ||
345 | ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path), | 343 | ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path), |
346 | ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path), | 344 | ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path), |
347 | ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path), | 345 | ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path), |
@@ -353,18 +351,10 @@ fn hover_for_definition( | |||
353 | }, | 351 | }, |
354 | Definition::Local(it) => hover_for_local(it, db), | 352 | Definition::Local(it) => hover_for_local(it, db), |
355 | Definition::SelfType(impl_def) => { | 353 | Definition::SelfType(impl_def) => { |
356 | impl_def.target_ty(db).as_adt().and_then(|adt| match adt { | 354 | impl_def.target_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path)) |
357 | Adt::Struct(it) => from_hir_fmt(db, it, mod_path), | ||
358 | Adt::Union(it) => from_hir_fmt(db, it, mod_path), | ||
359 | Adt::Enum(it) => from_hir_fmt(db, it, mod_path), | ||
360 | }) | ||
361 | } | 355 | } |
356 | Definition::GenericParam(it) => from_hir_fmt(db, it, None), | ||
362 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), | 357 | Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), |
363 | Definition::GenericParam(it) => match it { | ||
364 | GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))), | ||
365 | GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), | ||
366 | GenericParam::ConstParam(it) => Some(Markup::fenced_block(&it.display(db))), | ||
367 | }, | ||
368 | }; | 358 | }; |
369 | 359 | ||
370 | fn from_hir_fmt<D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> | 360 | fn from_hir_fmt<D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> |