aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-24 22:11:19 +0100
committerGitHub <[email protected]>2020-04-24 22:11:19 +0100
commit27a7718880d93f55f905da606d108d3b3c682ab4 (patch)
tree0e914349ddff41d2cbea342ee312efc9d4f37371 /crates/ra_ide/src
parent57b3dda980afba5dfb6e30e4716b7713ff0b1be0 (diff)
parente131763fb8b2e40ee2ad434bbb93b2ae43030390 (diff)
Merge #4128
4128: Include correct item path for variant completions r=matklad a=jonas-schievink The test would previously suggest `E::V`, which is not enough to name the variant as the enum is in a module. Now it correctly suggests the full path `m::E::V`. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion/complete_unqualified_path.rs53
1 files changed, 52 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs
index 638f86eda..8e3dcf96e 100644
--- a/crates/ra_ide/src/completion/complete_unqualified_path.rs
+++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs
@@ -38,7 +38,15 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext) {
38 if let Some(ty) = ctx.expected_type_of(&ctx.token.parent()) { 38 if let Some(ty) = ctx.expected_type_of(&ctx.token.parent()) {
39 if let Some(Adt::Enum(enum_data)) = ty.as_adt() { 39 if let Some(Adt::Enum(enum_data)) = ty.as_adt() {
40 let variants = enum_data.variants(ctx.db); 40 let variants = enum_data.variants(ctx.db);
41 let module = enum_data.module(ctx.db); 41
42 let module = if let Some(module) = ctx.scope().module() {
43 // Compute path from the completion site if available.
44 module
45 } else {
46 // Otherwise fall back to the enum's definition site.
47 enum_data.module(ctx.db)
48 };
49
42 for variant in variants { 50 for variant in variants {
43 if let Some(path) = module.find_use_path(ctx.db, ModuleDef::from(variant)) { 51 if let Some(path) = module.find_use_path(ctx.db, ModuleDef::from(variant)) {
44 // Variants with trivial paths are already added by the existing completion logic, 52 // Variants with trivial paths are already added by the existing completion logic,
@@ -1308,4 +1316,47 @@ mod tests {
1308 "### 1316 "###
1309 ) 1317 )
1310 } 1318 }
1319
1320 #[test]
1321 fn completes_enum_variant_from_module() {
1322 assert_debug_snapshot!(
1323 do_reference_completion(
1324 r"
1325 mod m { pub enum E { V } }
1326
1327 fn f() -> m::E {
1328 V<|>
1329 }
1330 "
1331 ),
1332 @r###"
1333 [
1334 CompletionItem {
1335 label: "f()",
1336 source_range: [98; 99),
1337 delete: [98; 99),
1338 insert: "f()$0",
1339 kind: Function,
1340 lookup: "f",
1341 detail: "fn f() -> m::E",
1342 },
1343 CompletionItem {
1344 label: "m",
1345 source_range: [98; 99),
1346 delete: [98; 99),
1347 insert: "m",
1348 kind: Module,
1349 },
1350 CompletionItem {
1351 label: "m::E::V",
1352 source_range: [98; 99),
1353 delete: [98; 99),
1354 insert: "m::E::V",
1355 kind: EnumVariant,
1356 detail: "()",
1357 },
1358 ]
1359 "###
1360 )
1361 }
1311} 1362}