expect![[r#"
fn public_method() fn()
ct PUBLIC_CONST pub const PUBLIC_CONST: u32
- ta PublicType pub type PublicType;
+ ta PublicType pub type PublicType = u32
"#]],
);
}
fn foo<T: Sub>() { T::$0 }
"#,
expect![[r#"
- ta SubTy (as Sub) type SubTy;
- ta Ty (as Super) type Ty;
+ ta SubTy (as Sub) type SubTy
+ ta Ty (as Super) type Ty
ct C2 (as Sub) const C2: ()
fn subfunc() (as Sub) fn()
me submethod(…) (as Sub) fn(&self)
}
"#,
expect![[r#"
- ta SubTy (as Sub) type SubTy;
- ta Ty (as Super) type Ty;
+ ta SubTy (as Sub) type SubTy
+ ta Ty (as Super) type Ty
ct CONST (as Super) const CONST: u8
fn func() (as Super) fn()
me method(…) (as Super) fn(&self)
//! Renderer for type aliases.
-use hir::{AsAssocItem, HasSource};
+use hir::{AsAssocItem, HirDisplay};
use ide_db::SymbolKind;
-use syntax::{ast::HasName, display::type_label};
use crate::{item::CompletionItem, render::RenderContext};
) -> Option<CompletionItem> {
let db = ctx.db();
- // FIXME: This parses the file!
- let ast_node = type_alias.source(db)?.value;
- let name = ast_node.name().map(|name| {
- if with_eq {
- format!("{} = ", name.text())
- } else {
- name.text().to_string()
- }
- })?;
- let detail = type_label(&ast_node);
+ // FIXME: smolstr?
+ let name = if with_eq {
+ format!("{} = ", type_alias.name(db))
+ } else {
+ type_alias.name(db).to_string()
+ };
+ let detail = type_alias.display(db).to_string();
let mut item = CompletionItem::new(SymbolKind::TypeAlias, ctx.source_range(), name.clone());
item.set_documentation(ctx.docs(type_alias))
ev UnitV ()
ct ASSOC_CONST const ASSOC_CONST: ()
fn assoc_fn() fn()
- ta AssocType type AssocType;
+ ta AssocType type AssocType = ()
"#]],
);
}
ev UnitV ()
ct ASSOC_CONST const ASSOC_CONST: ()
fn assoc_fn() fn()
- ta AssocType type AssocType;
+ ta AssocType type AssocType = ()
"#]],
);
}
kw self
kw super
kw crate
- ta Foo = (as Trait2) type Foo;
+ ta Foo = (as Trait2) type Foo
tp T
cp CONST_PARAM
tt Trait
fn func(_: Enum::$0) {}
"#,
expect![[r#"
- ta AssocType type AssocType;
+ ta AssocType type AssocType = ()
"#]],
);
}
buf
}
-pub fn type_label(node: &ast::TypeAlias) -> String {
- let mut s = String::new();
- if let Some(vis) = node.visibility() {
- format_to!(s, "{} ", vis);
- }
- format_to!(s, "type ");
- if let Some(name) = node.name() {
- format_to!(s, "{}", name);
- } else {
- format_to!(s, "?");
- }
- format_to!(s, ";");
- s
-}
-
pub fn macro_label(node: &ast::Macro) -> String {
let name = node.name();
let mut s = String::new();