Skip to content

Commit 7f7a364

Browse files
committed
Fully render type alias completions from hir
1 parent 40d5c58 commit 7f7a364

File tree

6 files changed

+17
-36
lines changed

6 files changed

+17
-36
lines changed

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn foo() { let _ = lib::S::$0 }
288288
expect![[r#"
289289
fn public_method() fn()
290290
ct PUBLIC_CONST pub const PUBLIC_CONST: u32
291-
ta PublicType pub type PublicType;
291+
ta PublicType pub type PublicType = u32
292292
"#]],
293293
);
294294
}
@@ -377,8 +377,8 @@ trait Sub: Super {
377377
fn foo<T: Sub>() { T::$0 }
378378
"#,
379379
expect![[r#"
380-
ta SubTy (as Sub) type SubTy;
381-
ta Ty (as Super) type Ty;
380+
ta SubTy (as Sub) type SubTy
381+
ta Ty (as Super) type Ty
382382
ct C2 (as Sub) const C2: ()
383383
fn subfunc() (as Sub) fn()
384384
me submethod(…) (as Sub) fn(&self)
@@ -417,8 +417,8 @@ impl<T> Sub for Wrap<T> {
417417
}
418418
"#,
419419
expect![[r#"
420-
ta SubTy (as Sub) type SubTy;
421-
ta Ty (as Super) type Ty;
420+
ta SubTy (as Sub) type SubTy
421+
ta Ty (as Super) type Ty
422422
ct CONST (as Super) const CONST: u8
423423
fn func() (as Super) fn()
424424
me method(…) (as Super) fn(&self)

crates/ide_completion/src/render/type_alias.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Renderer for type aliases.
22
3-
use hir::{AsAssocItem, HasSource};
3+
use hir::{AsAssocItem, HirDisplay};
44
use ide_db::SymbolKind;
5-
use syntax::{ast::HasName, display::type_label};
65

76
use crate::{item::CompletionItem, render::RenderContext};
87

@@ -29,16 +28,13 @@ fn render(
2928
) -> Option<CompletionItem> {
3029
let db = ctx.db();
3130

32-
// FIXME: This parses the file!
33-
let ast_node = type_alias.source(db)?.value;
34-
let name = ast_node.name().map(|name| {
35-
if with_eq {
36-
format!("{} = ", name.text())
37-
} else {
38-
name.text().to_string()
39-
}
40-
})?;
41-
let detail = type_label(&ast_node);
31+
// FIXME: smolstr?
32+
let name = if with_eq {
33+
format!("{} = ", type_alias.name(db))
34+
} else {
35+
type_alias.name(db).to_string()
36+
};
37+
let detail = type_alias.display(db).to_string();
4238

4339
let mut item = CompletionItem::new(SymbolKind::TypeAlias, ctx.source_range(), name.clone());
4440
item.set_documentation(ctx.docs(type_alias))

crates/ide_completion/src/tests/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ fn func() {
548548
ev UnitV ()
549549
ct ASSOC_CONST const ASSOC_CONST: ()
550550
fn assoc_fn() fn()
551-
ta AssocType type AssocType;
551+
ta AssocType type AssocType = ()
552552
"#]],
553553
);
554554
}

crates/ide_completion/src/tests/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn func() {
296296
ev UnitV ()
297297
ct ASSOC_CONST const ASSOC_CONST: ()
298298
fn assoc_fn() fn()
299-
ta AssocType type AssocType;
299+
ta AssocType type AssocType = ()
300300
"#]],
301301
);
302302
}

crates/ide_completion/src/tests/type_pos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
148148
kw self
149149
kw super
150150
kw crate
151-
ta Foo = (as Trait2) type Foo;
151+
ta Foo = (as Trait2) type Foo
152152
tp T
153153
cp CONST_PARAM
154154
tt Trait
@@ -199,7 +199,7 @@ impl Enum {
199199
fn func(_: Enum::$0) {}
200200
"#,
201201
expect![[r#"
202-
ta AssocType type AssocType;
202+
ta AssocType type AssocType = ()
203203
"#]],
204204
);
205205
}

crates/syntax/src/display.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ pub fn function_declaration(node: &ast::Fn) -> String {
5050
buf
5151
}
5252

53-
pub fn type_label(node: &ast::TypeAlias) -> String {
54-
let mut s = String::new();
55-
if let Some(vis) = node.visibility() {
56-
format_to!(s, "{} ", vis);
57-
}
58-
format_to!(s, "type ");
59-
if let Some(name) = node.name() {
60-
format_to!(s, "{}", name);
61-
} else {
62-
format_to!(s, "?");
63-
}
64-
format_to!(s, ";");
65-
s
66-
}
67-
6853
pub fn macro_label(node: &ast::Macro) -> String {
6954
let name = node.name();
7055
let mut s = String::new();

0 commit comments

Comments
 (0)