diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index b0edec56ff1..2b53d4a27bf 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -420,7 +420,7 @@ where E: Fn(&D) -> Option, V: Display, { - let label = if let Some(value) = (value_extractor)(&def) { + let label = if let Some(value) = value_extractor(&def) { format!("{} = {}", def.display(db), value) } else { def.display(db).to_string() diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 656d46b10be..8628de413b5 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -287,7 +287,7 @@ fn foo() { let _ = lib::S::$0 } "#, expect![[r#" fn public_method() fn() - ct PUBLIC_CONST pub const PUBLIC_CONST: u32; + ct PUBLIC_CONST pub const PUBLIC_CONST: u32 ta PublicType pub type PublicType; "#]], ); @@ -379,10 +379,10 @@ fn foo() { T::$0 } expect![[r#" ta SubTy (as Sub) type SubTy; ta Ty (as Super) type Ty; - ct C2 (as Sub) const C2: (); + ct C2 (as Sub) const C2: () fn subfunc() (as Sub) fn() me submethod(…) (as Sub) fn(&self) - ct CONST (as Super) const CONST: u8; + ct CONST (as Super) const CONST: u8 fn func() (as Super) fn() me method(…) (as Super) fn(&self) "#]], @@ -419,10 +419,10 @@ impl Sub for Wrap { expect![[r#" ta SubTy (as Sub) type SubTy; ta Ty (as Super) type Ty; - ct CONST (as Super) const CONST: u8; + ct CONST (as Super) const CONST: u8 fn func() (as Super) fn() me method(…) (as Super) fn(&self) - ct C2 (as Sub) const C2: (); + ct C2 (as Sub) const C2: () fn subfunc() (as Sub) fn() me submethod(…) (as Sub) fn(&self) "#]], @@ -653,7 +653,7 @@ impl u8 { } "#, expect![[r#" - ct MAX pub const MAX: Self; + ct MAX pub const MAX: Self me func(…) fn(self) "#]], ); diff --git a/crates/ide_completion/src/render/const_.rs b/crates/ide_completion/src/render/const_.rs index 65c9d1d63ed..4c8258f12c2 100644 --- a/crates/ide_completion/src/render/const_.rs +++ b/crates/ide_completion/src/render/const_.rs @@ -1,8 +1,7 @@ //! Renderer for `const` fields. -use hir::{AsAssocItem, HasSource}; +use hir::{AsAssocItem, HirDisplay}; use ide_db::SymbolKind; -use syntax::display::const_label; use crate::{item::CompletionItem, render::RenderContext}; @@ -14,8 +13,7 @@ pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option { let db = ctx.db(); let name = const_.name(db)?.to_smol_str(); - // FIXME: This is parsing files! - let detail = const_label(&const_.source(db)?.value); + let detail = const_.display(db).to_string(); let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone()); item.set_documentation(ctx.docs(const_)) diff --git a/crates/ide_completion/src/tests/expression.rs b/crates/ide_completion/src/tests/expression.rs index eba2a5e1efd..eb95bdcda95 100644 --- a/crates/ide_completion/src/tests/expression.rs +++ b/crates/ide_completion/src/tests/expression.rs @@ -546,7 +546,7 @@ fn func() { ev TupleV(…) (u32) ev RecordV {field: u32} ev UnitV () - ct ASSOC_CONST const ASSOC_CONST: (); + ct ASSOC_CONST const ASSOC_CONST: () fn assoc_fn() fn() ta AssocType type AssocType; "#]], diff --git a/crates/ide_completion/src/tests/pattern.rs b/crates/ide_completion/src/tests/pattern.rs index 99e20b6ed09..0e2d4088274 100644 --- a/crates/ide_completion/src/tests/pattern.rs +++ b/crates/ide_completion/src/tests/pattern.rs @@ -294,7 +294,7 @@ fn func() { ev TupleV(…) (u32) ev RecordV {field: u32} ev UnitV () - ct ASSOC_CONST const ASSOC_CONST: (); + ct ASSOC_CONST const ASSOC_CONST: () fn assoc_fn() fn() ta AssocType type AssocType; "#]], diff --git a/crates/syntax/src/display.rs b/crates/syntax/src/display.rs index e2115cbd2b0..10f1c901387 100644 --- a/crates/syntax/src/display.rs +++ b/crates/syntax/src/display.rs @@ -50,27 +50,6 @@ pub fn function_declaration(node: &ast::Fn) -> String { buf } -pub fn const_label(node: &ast::Const) -> String { - let mut s = String::new(); - if let Some(vis) = node.visibility() { - format_to!(s, "{} ", vis); - } - format_to!(s, "const "); - if let Some(name) = node.name() { - format_to!(s, "{}", name); - } else { - format_to!(s, "?"); - } - format_to!(s, ": "); - if let Some(ty) = node.ty() { - format_to!(s, "{}", ty); - } else { - format_to!(s, "?"); - } - format_to!(s, ";"); - s -} - pub fn type_label(node: &ast::TypeAlias) -> String { let mut s = String::new(); if let Some(vis) = node.visibility() {