Skip to content

Commit 943fa46

Browse files
committed
Alight details in comkplation list
1 parent c14a3b4 commit 943fa46

File tree

7 files changed

+63
-50
lines changed

7 files changed

+63
-50
lines changed

crates/ra_ide/src/completion/complete_dot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn foo(s: S) { s.<|> }
8383
"#,
8484
expect![[r#"
8585
me bar() fn bar(&self)
86-
fd foo u32
86+
fd foo u32
8787
"#]],
8888
);
8989
}
@@ -98,7 +98,7 @@ impl S {
9898
}
9999
"#,
100100
expect![[r#"
101-
me foo() fn foo(self)
101+
me foo() fn foo(self)
102102
fd the_field (u32,)
103103
"#]],
104104
)
@@ -114,7 +114,7 @@ impl A {
114114
}
115115
"#,
116116
expect![[r#"
117-
me foo() fn foo(&self)
117+
me foo() fn foo(&self)
118118
fd the_field (u32, i32)
119119
"#]],
120120
)
@@ -148,7 +148,7 @@ fn foo(a: inner::A) { a.<|> }
148148
"#,
149149
expect![[r#"
150150
fd crate_field u32
151-
fd pub_field u32
151+
fd pub_field u32
152152
fd super_field u32
153153
"#]],
154154
);

crates/ra_ide/src/completion/complete_keyword.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,17 @@ mod tests {
216216
check(
217217
r"use a::<|>",
218218
expect![[r#"
219-
kw self
220-
kw super::
221-
"#]],
219+
kw self
220+
kw super::
221+
"#]],
222222
);
223223

224224
check(
225225
r"use a::{b, <|>}",
226226
expect![[r#"
227-
kw self
228-
kw super::
229-
"#]],
227+
kw self
228+
kw super::
229+
"#]],
230230
);
231231
}
232232

crates/ra_ide/src/completion/complete_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn foo() {
6161
expect![[r#"
6262
st Bar
6363
en E
64-
ev X ()
64+
ev X ()
6565
ct Z
6666
md m
6767
"#]],

crates/ra_ide/src/completion/complete_postfix.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ fn main() {
260260
}
261261
"#,
262262
expect![[r#"
263-
sn box Box::new(expr)
264-
sn call function(expr)
265-
sn dbg dbg!(expr)
266-
sn if if expr {}
263+
sn box Box::new(expr)
264+
sn call function(expr)
265+
sn dbg dbg!(expr)
266+
sn if if expr {}
267267
sn match match expr {}
268-
sn not !expr
269-
sn ref &expr
270-
sn refm &mut expr
268+
sn not !expr
269+
sn ref &expr
270+
sn refm &mut expr
271271
sn while while expr {}
272272
"#]],
273273
);
@@ -283,12 +283,12 @@ fn main() {
283283
}
284284
"#,
285285
expect![[r#"
286-
sn box Box::new(expr)
287-
sn call function(expr)
288-
sn dbg dbg!(expr)
286+
sn box Box::new(expr)
287+
sn call function(expr)
288+
sn dbg dbg!(expr)
289289
sn match match expr {}
290-
sn ref &expr
291-
sn refm &mut expr
290+
sn ref &expr
291+
sn refm &mut expr
292292
"#]],
293293
)
294294
}

crates/ra_ide/src/completion/complete_qualified_path.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn foo() { let _ = E::<|> }
332332
"#,
333333
expect![[r#"
334334
ev Bar(…) (i32)
335-
ev Foo ()
335+
ev Foo ()
336336
"#]],
337337
);
338338
}
@@ -354,8 +354,8 @@ impl S {
354354
fn foo() { let _ = S::<|> }
355355
"#,
356356
expect![[r#"
357-
ct C const C: i32 = 42;
358-
ta T type T = i32;
357+
ct C const C: i32 = 42;
358+
ta T type T = i32;
359359
fn a() fn a()
360360
me b() fn b(&self)
361361
"#]],
@@ -382,8 +382,8 @@ mod m {
382382
fn foo() { let _ = S::<|> }
383383
"#,
384384
expect![[r#"
385-
ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1;
386-
ta PublicType pub(super) type PublicType = u32;
385+
ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1;
386+
ta PublicType pub(super) type PublicType = u32;
387387
fn public_method() pub(super) fn public_method()
388388
"#]],
389389
);
@@ -504,13 +504,13 @@ trait Sub: Super {
504504
fn foo<T: Sub>() { T::<|> }
505505
"#,
506506
expect![[r#"
507-
ct C2 const C2: ();
508-
ct CONST const CONST: u8;
509-
ta SubTy type SubTy;
510-
ta Ty type Ty;
511-
fn func() fn func()
512-
me method() fn method(&self)
513-
fn subfunc() fn subfunc()
507+
ct C2 const C2: ();
508+
ct CONST const CONST: u8;
509+
ta SubTy type SubTy;
510+
ta Ty type Ty;
511+
fn func() fn func()
512+
me method() fn method(&self)
513+
fn subfunc() fn subfunc()
514514
me submethod() fn submethod(&self)
515515
"#]],
516516
);
@@ -544,13 +544,13 @@ impl<T> Sub for Wrap<T> {
544544
}
545545
"#,
546546
expect![[r#"
547-
ct C2 const C2: () = ();
548-
ct CONST const CONST: u8 = 0;
549-
ta SubTy type SubTy;
550-
ta Ty type Ty;
551-
fn func() fn func()
552-
me method() fn method(&self)
553-
fn subfunc() fn subfunc()
547+
ct C2 const C2: () = ();
548+
ct CONST const CONST: u8 = 0;
549+
ta SubTy type SubTy;
550+
ta Ty type Ty;
551+
fn func() fn func()
552+
me method() fn method(&self)
553+
fn subfunc() fn subfunc()
554554
me submethod() fn submethod(&self)
555555
"#]],
556556
);
@@ -586,7 +586,7 @@ fn main() { let _ = crate::<|> }
586586
expect![[r##"
587587
ma foo!(…) #[macro_export]
588588
macro_rules! foo
589-
fn main() fn main()
589+
fn main() fn main()
590590
"##]],
591591
);
592592
}
@@ -630,7 +630,7 @@ mod p {
630630
expect![[r#"
631631
ct RIGHT_CONST
632632
st RightType
633-
fn right_fn() fn wrong_fn()
633+
fn right_fn() fn wrong_fn()
634634
"#]],
635635
);
636636

@@ -676,7 +676,7 @@ fn main() { m!(self::f<|>); }
676676
fn foo() {}
677677
"#,
678678
expect![[r#"
679-
fn foo() fn foo()
679+
fn foo() fn foo()
680680
fn main() fn main()
681681
"#]],
682682
);

crates/ra_ide/src/completion/complete_snippet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ mod tests {
8484
check(
8585
r#"fn foo(x: i32) { <|> }"#,
8686
expect![[r#"
87-
sn pd
88-
sn ppd
89-
"#]],
87+
sn pd
88+
sn ppd
89+
"#]],
9090
);
9191
}
9292

crates/ra_ide/src/completion/test_utils.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,32 @@ pub(crate) fn completion_list_with_config(
4343
.filter(|c| c.completion_kind == kind)
4444
.collect();
4545
kind_completions.sort_by_key(|c| c.label().to_owned());
46+
let label_width = kind_completions
47+
.iter()
48+
.map(|it| monospace_width(it.label()))
49+
.max()
50+
.unwrap_or_default()
51+
.min(16);
4652
kind_completions
4753
.into_iter()
4854
.map(|it| {
49-
let mut buf = format!("{} {}", it.kind().unwrap().tag(), it.label());
55+
let tag = it.kind().unwrap().tag();
56+
let var_name = format!("{} {}", tag, it.label());
57+
let mut buf = var_name;
5058
if let Some(detail) = it.detail() {
51-
format_to!(buf, " {}", detail);
59+
let width = label_width.saturating_sub(monospace_width(it.label()));
60+
format_to!(buf, "{:width$} {}", "", detail, width = width);
5261
}
5362
format_to!(buf, "\n");
5463
buf
5564
})
5665
.collect()
5766
}
5867

68+
fn monospace_width(s: &str) -> usize {
69+
s.chars().count()
70+
}
71+
5972
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
6073
check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default())
6174
}

0 commit comments

Comments
 (0)