mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Fully render const item completions from hir
This commit is contained in:
parent
929cae74b1
commit
40d5c58a80
6 changed files with 11 additions and 34 deletions
|
@ -420,7 +420,7 @@ where
|
||||||
E: Fn(&D) -> Option<V>,
|
E: Fn(&D) -> Option<V>,
|
||||||
V: Display,
|
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)
|
format!("{} = {}", def.display(db), value)
|
||||||
} else {
|
} else {
|
||||||
def.display(db).to_string()
|
def.display(db).to_string()
|
||||||
|
|
|
@ -287,7 +287,7 @@ fn foo() { let _ = lib::S::$0 }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
fn public_method() fn()
|
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;
|
ta PublicType pub type PublicType;
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -379,10 +379,10 @@ fn foo<T: Sub>() { T::$0 }
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
ta SubTy (as Sub) type SubTy;
|
ta SubTy (as Sub) type SubTy;
|
||||||
ta Ty (as Super) type Ty;
|
ta Ty (as Super) type Ty;
|
||||||
ct C2 (as Sub) const C2: ();
|
ct C2 (as Sub) const C2: ()
|
||||||
fn subfunc() (as Sub) fn()
|
fn subfunc() (as Sub) fn()
|
||||||
me submethod(…) (as Sub) fn(&self)
|
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()
|
fn func() (as Super) fn()
|
||||||
me method(…) (as Super) fn(&self)
|
me method(…) (as Super) fn(&self)
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -419,10 +419,10 @@ impl<T> Sub for Wrap<T> {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
ta SubTy (as Sub) type SubTy;
|
ta SubTy (as Sub) type SubTy;
|
||||||
ta Ty (as Super) type Ty;
|
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()
|
fn func() (as Super) fn()
|
||||||
me method(…) (as Super) fn(&self)
|
me method(…) (as Super) fn(&self)
|
||||||
ct C2 (as Sub) const C2: ();
|
ct C2 (as Sub) const C2: ()
|
||||||
fn subfunc() (as Sub) fn()
|
fn subfunc() (as Sub) fn()
|
||||||
me submethod(…) (as Sub) fn(&self)
|
me submethod(…) (as Sub) fn(&self)
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -653,7 +653,7 @@ impl u8 {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
ct MAX pub const MAX: Self;
|
ct MAX pub const MAX: Self
|
||||||
me func(…) fn(self)
|
me func(…) fn(self)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
//! Renderer for `const` fields.
|
//! Renderer for `const` fields.
|
||||||
|
|
||||||
use hir::{AsAssocItem, HasSource};
|
use hir::{AsAssocItem, HirDisplay};
|
||||||
use ide_db::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
use syntax::display::const_label;
|
|
||||||
|
|
||||||
use crate::{item::CompletionItem, render::RenderContext};
|
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<CompletionItem> {
|
fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
|
||||||
let db = ctx.db();
|
let db = ctx.db();
|
||||||
let name = const_.name(db)?.to_smol_str();
|
let name = const_.name(db)?.to_smol_str();
|
||||||
// FIXME: This is parsing files!
|
let detail = const_.display(db).to_string();
|
||||||
let detail = const_label(&const_.source(db)?.value);
|
|
||||||
|
|
||||||
let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone());
|
let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone());
|
||||||
item.set_documentation(ctx.docs(const_))
|
item.set_documentation(ctx.docs(const_))
|
||||||
|
|
|
@ -546,7 +546,7 @@ fn func() {
|
||||||
ev TupleV(…) (u32)
|
ev TupleV(…) (u32)
|
||||||
ev RecordV {field: u32}
|
ev RecordV {field: u32}
|
||||||
ev UnitV ()
|
ev UnitV ()
|
||||||
ct ASSOC_CONST const ASSOC_CONST: ();
|
ct ASSOC_CONST const ASSOC_CONST: ()
|
||||||
fn assoc_fn() fn()
|
fn assoc_fn() fn()
|
||||||
ta AssocType type AssocType;
|
ta AssocType type AssocType;
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
@ -294,7 +294,7 @@ fn func() {
|
||||||
ev TupleV(…) (u32)
|
ev TupleV(…) (u32)
|
||||||
ev RecordV {field: u32}
|
ev RecordV {field: u32}
|
||||||
ev UnitV ()
|
ev UnitV ()
|
||||||
ct ASSOC_CONST const ASSOC_CONST: ();
|
ct ASSOC_CONST const ASSOC_CONST: ()
|
||||||
fn assoc_fn() fn()
|
fn assoc_fn() fn()
|
||||||
ta AssocType type AssocType;
|
ta AssocType type AssocType;
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
@ -50,27 +50,6 @@ pub fn function_declaration(node: &ast::Fn) -> String {
|
||||||
buf
|
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 {
|
pub fn type_label(node: &ast::TypeAlias) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
if let Some(vis) = node.visibility() {
|
if let Some(vis) = node.visibility() {
|
||||||
|
|
Loading…
Reference in a new issue