Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/hover/render.rs')
| -rw-r--r-- | crates/ide/src/hover/render.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index a7c50081e4..dc03df180a 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -43,13 +43,17 @@ pub(super) fn type_info_of( pub(super) fn closure_expr( sema: &Semantics<'_, RootDatabase>, + config: &HoverConfig, c: ast::ClosureExpr, ) -> Option<HoverResult> { let ty = &sema.type_of_expr(&c.into())?.original; - let layout = ty - .layout(sema.db) - .map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes())) - .unwrap_or_default(); + let layout = if config.memory_layout { + ty.layout(sema.db) + .map(|x| format!(" // size = {}, align = {}", x.size.bytes(), x.align.abi.bytes())) + .unwrap_or_default() + } else { + String::default() + }; let c = ty.as_closure()?; let mut captures = c .captured_items(sema.db) @@ -415,7 +419,7 @@ pub(super) fn definition( let mod_path = definition_mod_path(db, &def); let (label, docs) = match def { Definition::Macro(it) => label_and_docs(db, it), - Definition::Field(it) => label_and_layout_info_and_docs(db, it, |&it| { + Definition::Field(it) => label_and_layout_info_and_docs(db, it, config, |&it| { let var_def = it.parent_def(db); let id = it.index(); let layout = it.layout(db).ok()?; @@ -435,7 +439,7 @@ pub(super) fn definition( }), Definition::Module(it) => label_and_docs(db, it), Definition::Function(it) => label_and_docs(db, it), - Definition::Adt(it) => label_and_layout_info_and_docs(db, it, |&it| { + Definition::Adt(it) => label_and_layout_info_and_docs(db, it, config, |&it| { let layout = it.layout(db).ok()?; Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes())) }), @@ -473,7 +477,7 @@ pub(super) fn definition( }), Definition::Trait(it) => label_and_docs(db, it), Definition::TraitAlias(it) => label_and_docs(db, it), - Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, |&it| { + Definition::TypeAlias(it) => label_and_layout_info_and_docs(db, it, config, |&it| { let layout = it.ty(db).layout(db).ok()?; Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes())) }), @@ -577,6 +581,7 @@ where fn label_and_layout_info_and_docs<D, E, V>( db: &RootDatabase, def: D, + config: &HoverConfig, value_extractor: E, ) -> (String, Option<hir::Documentation>) where @@ -584,10 +589,9 @@ where E: Fn(&D) -> Option<V>, V: Display, { - let label = if let Some(value) = value_extractor(&def) { - format!("{} // {value}", def.display(db)) - } else { - def.display(db).to_string() + let label = match value_extractor(&def) { + Some(value) if config.memory_layout => format!("{} // {value}", def.display(db)), + _ => def.display(db).to_string(), }; let docs = def.attrs(db).docs(); (label, docs) |