mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Complete variants when only enun name is typed
This allows the client to filter `Foo::Bar` when *either* `Foo` or `Bar` is typed.
This commit is contained in:
parent
dd8a75b2cf
commit
f9b81369e2
1 changed files with 62 additions and 8 deletions
|
@ -304,9 +304,14 @@ impl Completions {
|
||||||
) {
|
) {
|
||||||
let is_deprecated = is_deprecated(variant, ctx.db);
|
let is_deprecated = is_deprecated(variant, ctx.db);
|
||||||
let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string());
|
let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string());
|
||||||
let qualified_name = match &path {
|
let (qualified_name, short_qualified_name) = match &path {
|
||||||
Some(it) => it.to_string(),
|
Some(path) => {
|
||||||
None => name.to_string(),
|
let full = path.to_string();
|
||||||
|
let short =
|
||||||
|
path.segments[path.segments.len().saturating_sub(2)..].iter().join("::");
|
||||||
|
(full, short)
|
||||||
|
}
|
||||||
|
None => (name.to_string(), name.to_string()),
|
||||||
};
|
};
|
||||||
let detail_types = variant
|
let detail_types = variant
|
||||||
.fields(ctx.db)
|
.fields(ctx.db)
|
||||||
|
@ -335,14 +340,12 @@ impl Completions {
|
||||||
.set_deprecated(is_deprecated)
|
.set_deprecated(is_deprecated)
|
||||||
.detail(detail);
|
.detail(detail);
|
||||||
|
|
||||||
if path.is_some() {
|
|
||||||
res = res.lookup_by(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if variant_kind == StructKind::Tuple {
|
if variant_kind == StructKind::Tuple {
|
||||||
mark::hit!(inserts_parens_for_tuple_enums);
|
mark::hit!(inserts_parens_for_tuple_enums);
|
||||||
let params = Params::Anonymous(variant.fields(ctx.db).len());
|
let params = Params::Anonymous(variant.fields(ctx.db).len());
|
||||||
res = res.add_call_parens(ctx, qualified_name, params)
|
res = res.add_call_parens(ctx, short_qualified_name, params)
|
||||||
|
} else if path.is_some() {
|
||||||
|
res = res.lookup_by(short_qualified_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.add_to(self);
|
res.add_to(self);
|
||||||
|
@ -606,6 +609,57 @@ fn main() { Foo::Fo<|> }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lookup_enums_by_two_qualifiers() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod m {
|
||||||
|
pub enum Spam { Foo, Bar(i32) }
|
||||||
|
}
|
||||||
|
fn main() { let _: m::Spam = S<|> }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "Spam::Bar(…)",
|
||||||
|
source_range: 75..76,
|
||||||
|
delete: 75..76,
|
||||||
|
insert: "Spam::Bar($0)",
|
||||||
|
kind: EnumVariant,
|
||||||
|
lookup: "Spam::Bar",
|
||||||
|
detail: "(i32)",
|
||||||
|
trigger_call_info: true,
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "m",
|
||||||
|
source_range: 75..76,
|
||||||
|
delete: 75..76,
|
||||||
|
insert: "m",
|
||||||
|
kind: Module,
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "m::Spam::Foo",
|
||||||
|
source_range: 75..76,
|
||||||
|
delete: 75..76,
|
||||||
|
insert: "m::Spam::Foo",
|
||||||
|
kind: EnumVariant,
|
||||||
|
lookup: "Spam::Foo",
|
||||||
|
detail: "()",
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "main()",
|
||||||
|
source_range: 75..76,
|
||||||
|
delete: 75..76,
|
||||||
|
insert: "main()$0",
|
||||||
|
kind: Function,
|
||||||
|
lookup: "main",
|
||||||
|
detail: "fn main()",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sets_deprecated_flag_in_completion_items() {
|
fn sets_deprecated_flag_in_completion_items() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue