Merge #5225
5225: Alight details in comkplation list r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
c815d5b496
@ -2,6 +2,9 @@ mod completion_config;
|
|||||||
mod completion_item;
|
mod completion_item;
|
||||||
mod completion_context;
|
mod completion_context;
|
||||||
mod presentation;
|
mod presentation;
|
||||||
|
mod patterns;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_utils;
|
||||||
|
|
||||||
mod complete_attribute;
|
mod complete_attribute;
|
||||||
mod complete_dot;
|
mod complete_dot;
|
||||||
@ -15,9 +18,6 @@ mod complete_unqualified_path;
|
|||||||
mod complete_postfix;
|
mod complete_postfix;
|
||||||
mod complete_macro_in_item_position;
|
mod complete_macro_in_item_position;
|
||||||
mod complete_trait_impl;
|
mod complete_trait_impl;
|
||||||
mod patterns;
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test_utils;
|
|
||||||
|
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::RootDatabase;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ fn foo(s: S) { s.<|> }
|
|||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
me bar() fn bar(&self)
|
me bar() fn bar(&self)
|
||||||
fd foo u32
|
fd foo u32
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ impl S {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
me foo() fn foo(self)
|
me foo() fn foo(self)
|
||||||
fd the_field (u32,)
|
fd the_field (u32,)
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
@ -114,7 +114,7 @@ impl A {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
me foo() fn foo(&self)
|
me foo() fn foo(&self)
|
||||||
fd the_field (u32, i32)
|
fd the_field (u32, i32)
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
@ -148,7 +148,7 @@ fn foo(a: inner::A) { a.<|> }
|
|||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
fd crate_field u32
|
fd crate_field u32
|
||||||
fd pub_field u32
|
fd pub_field u32
|
||||||
fd super_field u32
|
fd super_field u32
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -216,17 +216,17 @@ mod tests {
|
|||||||
check(
|
check(
|
||||||
r"use a::<|>",
|
r"use a::<|>",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
||||||
check(
|
check(
|
||||||
r"use a::{b, <|>}",
|
r"use a::{b, <|>}",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ fn foo() {
|
|||||||
expect![[r#"
|
expect![[r#"
|
||||||
st Bar
|
st Bar
|
||||||
en E
|
en E
|
||||||
ev X ()
|
ev X ()
|
||||||
ct Z
|
ct Z
|
||||||
md m
|
md m
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -260,14 +260,14 @@ fn main() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
sn box Box::new(expr)
|
sn box Box::new(expr)
|
||||||
sn call function(expr)
|
sn call function(expr)
|
||||||
sn dbg dbg!(expr)
|
sn dbg dbg!(expr)
|
||||||
sn if if expr {}
|
sn if if expr {}
|
||||||
sn match match expr {}
|
sn match match expr {}
|
||||||
sn not !expr
|
sn not !expr
|
||||||
sn ref &expr
|
sn ref &expr
|
||||||
sn refm &mut expr
|
sn refm &mut expr
|
||||||
sn while while expr {}
|
sn while while expr {}
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
@ -283,12 +283,12 @@ fn main() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
sn box Box::new(expr)
|
sn box Box::new(expr)
|
||||||
sn call function(expr)
|
sn call function(expr)
|
||||||
sn dbg dbg!(expr)
|
sn dbg dbg!(expr)
|
||||||
sn match match expr {}
|
sn match match expr {}
|
||||||
sn ref &expr
|
sn ref &expr
|
||||||
sn refm &mut expr
|
sn refm &mut expr
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -70,95 +70,47 @@ fn ${1:feature}() {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
use expect::{expect, Expect};
|
||||||
use insta::assert_debug_snapshot;
|
|
||||||
|
|
||||||
fn do_snippet_completion(code: &str) -> Vec<CompletionItem> {
|
use crate::completion::{test_utils::completion_list, CompletionKind};
|
||||||
do_completion(code, CompletionKind::Snippet)
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
let actual = completion_list(ra_fixture, CompletionKind::Snippet);
|
||||||
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_snippets_in_expressions() {
|
fn completes_snippets_in_expressions() {
|
||||||
assert_debug_snapshot!(
|
check(
|
||||||
do_snippet_completion(r"fn foo(x: i32) { <|> }"),
|
r#"fn foo(x: i32) { <|> }"#,
|
||||||
@r###"
|
expect![[r#"
|
||||||
[
|
sn pd
|
||||||
CompletionItem {
|
sn ppd
|
||||||
label: "pd",
|
"#]],
|
||||||
source_range: 17..17,
|
);
|
||||||
delete: 17..17,
|
|
||||||
insert: "eprintln!(\"$0 = {:?}\", $0);",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "ppd",
|
|
||||||
source_range: 17..17,
|
|
||||||
delete: 17..17,
|
|
||||||
insert: "eprintln!(\"$0 = {:#?}\", $0);",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_not_complete_snippets_in_path() {
|
fn should_not_complete_snippets_in_path() {
|
||||||
assert_debug_snapshot!(
|
check(r#"fn foo(x: i32) { ::foo<|> }"#, expect![[""]]);
|
||||||
do_snippet_completion(r"fn foo(x: i32) { ::foo<|> }"),
|
check(r#"fn foo(x: i32) { ::<|> }"#, expect![[""]]);
|
||||||
@"[]"
|
|
||||||
);
|
|
||||||
assert_debug_snapshot!(
|
|
||||||
do_snippet_completion(r"fn foo(x: i32) { ::<|> }"),
|
|
||||||
@"[]"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_snippets_in_items() {
|
fn completes_snippets_in_items() {
|
||||||
assert_debug_snapshot!(
|
check(
|
||||||
do_snippet_completion(
|
r#"
|
||||||
r"
|
#[cfg(test)]
|
||||||
#[cfg(test)]
|
mod tests {
|
||||||
mod tests {
|
<|>
|
||||||
<|>
|
}
|
||||||
}
|
"#,
|
||||||
"
|
expect![[r#"
|
||||||
),
|
sn Test function
|
||||||
@r###"
|
sn Test module
|
||||||
[
|
sn macro_rules
|
||||||
CompletionItem {
|
sn pub(crate)
|
||||||
label: "Test function",
|
"#]],
|
||||||
source_range: 29..29,
|
)
|
||||||
delete: 29..29,
|
|
||||||
insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
|
|
||||||
kind: Snippet,
|
|
||||||
lookup: "tfn",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "Test module",
|
|
||||||
source_range: 29..29,
|
|
||||||
delete: 29..29,
|
|
||||||
insert: "#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn ${1:test_name}() {\n $0\n }\n}",
|
|
||||||
kind: Snippet,
|
|
||||||
lookup: "tmod",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "macro_rules",
|
|
||||||
source_range: 29..29,
|
|
||||||
delete: 29..29,
|
|
||||||
insert: "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "pub(crate)",
|
|
||||||
source_range: 29..29,
|
|
||||||
delete: 29..29,
|
|
||||||
insert: "pub(crate) $0",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -683,6 +683,57 @@ impl S {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
use self::my<|>;
|
||||||
|
|
||||||
|
/// mod docs
|
||||||
|
mod my { }
|
||||||
|
|
||||||
|
/// enum docs
|
||||||
|
enum E {
|
||||||
|
/// variant docs
|
||||||
|
V
|
||||||
|
}
|
||||||
|
use self::E::*;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "E",
|
||||||
|
source_range: 10..12,
|
||||||
|
delete: 10..12,
|
||||||
|
insert: "E",
|
||||||
|
kind: Enum,
|
||||||
|
documentation: Documentation(
|
||||||
|
"enum docs",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "V",
|
||||||
|
source_range: 10..12,
|
||||||
|
delete: 10..12,
|
||||||
|
insert: "V",
|
||||||
|
kind: EnumVariant,
|
||||||
|
detail: "()",
|
||||||
|
documentation: Documentation(
|
||||||
|
"variant docs",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "my",
|
||||||
|
source_range: 10..12,
|
||||||
|
delete: 10..12,
|
||||||
|
insert: "my",
|
||||||
|
kind: Module,
|
||||||
|
documentation: Documentation(
|
||||||
|
"mod docs",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,12 +43,21 @@ pub(crate) fn completion_list_with_config(
|
|||||||
.filter(|c| c.completion_kind == kind)
|
.filter(|c| c.completion_kind == kind)
|
||||||
.collect();
|
.collect();
|
||||||
kind_completions.sort_by_key(|c| c.label().to_owned());
|
kind_completions.sort_by_key(|c| c.label().to_owned());
|
||||||
|
let label_width = kind_completions
|
||||||
|
.iter()
|
||||||
|
.map(|it| monospace_width(it.label()))
|
||||||
|
.max()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.min(16);
|
||||||
kind_completions
|
kind_completions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|it| {
|
.map(|it| {
|
||||||
let mut buf = format!("{} {}", it.kind().unwrap().tag(), it.label());
|
let tag = it.kind().unwrap().tag();
|
||||||
|
let var_name = format!("{} {}", tag, it.label());
|
||||||
|
let mut buf = var_name;
|
||||||
if let Some(detail) = it.detail() {
|
if let Some(detail) = it.detail() {
|
||||||
format_to!(buf, " {}", detail);
|
let width = label_width.saturating_sub(monospace_width(it.label()));
|
||||||
|
format_to!(buf, "{:width$} {}", "", detail, width = width);
|
||||||
}
|
}
|
||||||
format_to!(buf, "\n");
|
format_to!(buf, "\n");
|
||||||
buf
|
buf
|
||||||
@ -56,6 +65,10 @@ pub(crate) fn completion_list_with_config(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn monospace_width(s: &str) -> usize {
|
||||||
|
s.chars().count()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||||
check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default())
|
check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user