aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKevin DeLorey <[email protected]>2020-02-13 02:46:12 +0000
committerKevin DeLorey <[email protected]>2020-02-13 02:46:55 +0000
commit43e62a87ab97f946f3d2da2db0aa0b1f0ef7d8bf (patch)
treea7678a16f1b6e592c9d59a672b885c36870f6d59 /crates
parent877cfbacf98d9d803aa5e0f54be560c7da7acbca (diff)
Cheese const tests as they requre an ident before becoming a CONST_DEF.
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs49
1 files changed, 21 insertions, 28 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index b1017e57a..912bf789e 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -16,15 +16,10 @@ use ra_syntax::{
16use ra_assists::utils::get_missing_impl_items; 16use ra_assists::utils::get_missing_impl_items;
17 17
18pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { 18pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
19 let trigger = ctx.token 19 let trigger = ctx.token.ancestors().find(|p| match p.kind() {
20 .ancestors() 20 SyntaxKind::FN_DEF | SyntaxKind::TYPE_ALIAS_DEF | SyntaxKind::CONST_DEF => true,
21 .find(|p| match p.kind() { 21 _ => false,
22 SyntaxKind::FN_DEF | 22 });
23 SyntaxKind::TYPE_ALIAS_DEF |
24 SyntaxKind::CONST_DEF |
25 SyntaxKind::ITEM_LIST => true,
26 _ => false
27 });
28 23
29 let impl_block = trigger 24 let impl_block = trigger
30 .as_ref() 25 .as_ref()
@@ -37,40 +32,38 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
37 SyntaxKind::FN_DEF => { 32 SyntaxKind::FN_DEF => {
38 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block) 33 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block)
39 .iter() 34 .iter()
40 .filter_map(|item| { 35 .filter_map(|item| match item {
41 match item { 36 hir::AssocItem::Function(fn_item) => Some(fn_item),
42 hir::AssocItem::Function(fn_item) => Some(fn_item), 37 _ => None,
43 _ => None 38 })
44 }
45 })
46 { 39 {
47 add_function_impl(acc, ctx, &missing_fn); 40 add_function_impl(acc, ctx, &missing_fn);
48 } 41 }
49 }, 42 }
50 43
51 SyntaxKind::TYPE_ALIAS_DEF => { 44 SyntaxKind::TYPE_ALIAS_DEF => {
52 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block) 45 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block)
53 .iter() 46 .iter()
54 .filter_map(|item| match item { 47 .filter_map(|item| match item {
55 hir::AssocItem::TypeAlias(type_item) => Some(type_item), 48 hir::AssocItem::TypeAlias(type_item) => Some(type_item),
56 _ => None 49 _ => None,
57 }) 50 })
58 { 51 {
59 add_type_alias_impl(acc, ctx, &missing_fn); 52 add_type_alias_impl(acc, ctx, &missing_fn);
60 } 53 }
61 }, 54 }
62 55
63 SyntaxKind::CONST_DEF => { 56 SyntaxKind::CONST_DEF => {
64 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block) 57 for missing_fn in get_missing_impl_items(ctx.db, &ctx.analyzer, &impl_block)
65 .iter() 58 .iter()
66 .filter_map(|item| match item { 59 .filter_map(|item| match item {
67 hir::AssocItem::Const(const_item) => Some(const_item), 60 hir::AssocItem::Const(const_item) => Some(const_item),
68 _ => None 61 _ => None,
69 }) 62 })
70 { 63 {
71 add_const_impl(acc, ctx, &missing_fn); 64 add_const_impl(acc, ctx, &missing_fn);
72 } 65 }
73 }, 66 }
74 67
75 _ => {} 68 _ => {}
76 } 69 }
@@ -309,7 +302,7 @@ mod tests {
309 } 302 }
310 303
311 impl Test for () { 304 impl Test for () {
312 const<|> 305 const S<|>
313 } 306 }
314 ", 307 ",
315 ); 308 );
@@ -317,8 +310,8 @@ mod tests {
317 [ 310 [
318 CompletionItem { 311 CompletionItem {
319 label: "const SOME_CONST: u16 = ", 312 label: "const SOME_CONST: u16 = ",
320 source_range: [132; 132), 313 source_range: [133; 134),
321 delete: [132; 132), 314 delete: [133; 134),
322 insert: "const SOME_CONST: u16 = ", 315 insert: "const SOME_CONST: u16 = ",
323 kind: Const, 316 kind: Const,
324 }, 317 },
@@ -335,7 +328,7 @@ mod tests {
335 } 328 }
336 329
337 impl Test for () { 330 impl Test for () {
338 const<|> 331 const S<|>
339 } 332 }
340 ", 333 ",
341 ); 334 );
@@ -343,8 +336,8 @@ mod tests {
343 [ 336 [
344 CompletionItem { 337 CompletionItem {
345 label: "const SOME_CONST: u16 = ", 338 label: "const SOME_CONST: u16 = ",
346 source_range: [137; 137), 339 source_range: [138; 139),
347 delete: [137; 137), 340 delete: [138; 139),
348 insert: "const SOME_CONST: u16 = ", 341 insert: "const SOME_CONST: u16 = ",
349 kind: Const, 342 kind: Const,
350 }, 343 },