aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs50
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs8
2 files changed, 26 insertions, 32 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index 9a27c164b..18a1d2995 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -3,7 +3,7 @@
3//! This module adds the completion items related to implementing associated 3//! This module adds the completion items related to implementing associated
4//! items within a `impl Trait for Struct` block. The current context node 4//! items within a `impl Trait for Struct` block. The current context node
5//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node 5//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node
6//! and an direct child of an `IMPL_BLOCK`. 6//! and an direct child of an `IMPL_DEF`.
7//! 7//!
8//! # Examples 8//! # Examples
9//! 9//!
@@ -55,49 +55,43 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
55 _ => false, 55 _ => false,
56 }); 56 });
57 57
58 let impl_block = trigger 58 let impl_def = trigger
59 .as_ref() 59 .as_ref()
60 .and_then(|node| node.parent()) 60 .and_then(|node| node.parent())
61 .and_then(|node| node.parent()) 61 .and_then(|node| node.parent())
62 .and_then(ast::ImplBlock::cast); 62 .and_then(ast::ImplDef::cast);
63 63
64 if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) { 64 if let (Some(trigger), Some(impl_def)) = (trigger, impl_def) {
65 match trigger.kind() { 65 match trigger.kind() {
66 SyntaxKind::FN_DEF => { 66 SyntaxKind::FN_DEF => {
67 for missing_fn in 67 for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
68 get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { 68 |item| match item {
69 match item { 69 hir::AssocItem::Function(fn_item) => Some(fn_item),
70 hir::AssocItem::Function(fn_item) => Some(fn_item), 70 _ => None,
71 _ => None, 71 },
72 } 72 ) {
73 })
74 {
75 add_function_impl(&trigger, acc, ctx, &missing_fn); 73 add_function_impl(&trigger, acc, ctx, &missing_fn);
76 } 74 }
77 } 75 }
78 76
79 SyntaxKind::TYPE_ALIAS_DEF => { 77 SyntaxKind::TYPE_ALIAS_DEF => {
80 for missing_fn in 78 for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
81 get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { 79 |item| match item {
82 match item { 80 hir::AssocItem::TypeAlias(type_item) => Some(type_item),
83 hir::AssocItem::TypeAlias(type_item) => Some(type_item), 81 _ => None,
84 _ => None, 82 },
85 } 83 ) {
86 })
87 {
88 add_type_alias_impl(&trigger, acc, ctx, &missing_fn); 84 add_type_alias_impl(&trigger, acc, ctx, &missing_fn);
89 } 85 }
90 } 86 }
91 87
92 SyntaxKind::CONST_DEF => { 88 SyntaxKind::CONST_DEF => {
93 for missing_fn in 89 for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map(
94 get_missing_impl_items(&ctx.sema, &impl_block).iter().filter_map(|item| { 90 |item| match item {
95 match item { 91 hir::AssocItem::Const(const_item) => Some(const_item),
96 hir::AssocItem::Const(const_item) => Some(const_item), 92 _ => None,
97 _ => None, 93 },
98 } 94 ) {
99 })
100 {
101 add_const_impl(&trigger, acc, ctx, &missing_fn); 95 add_const_impl(&trigger, acc, ctx, &missing_fn);
102 } 96 }
103 } 97 }
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 81321a897..9aa5a705d 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -27,7 +27,7 @@ pub(crate) struct CompletionContext<'a> {
27 pub(super) use_item_syntax: Option<ast::UseItem>, 27 pub(super) use_item_syntax: Option<ast::UseItem>,
28 pub(super) record_lit_syntax: Option<ast::RecordLit>, 28 pub(super) record_lit_syntax: Option<ast::RecordLit>,
29 pub(super) record_lit_pat: Option<ast::RecordPat>, 29 pub(super) record_lit_pat: Option<ast::RecordPat>,
30 pub(super) impl_block: Option<ast::ImplBlock>, 30 pub(super) impl_def: Option<ast::ImplDef>,
31 pub(super) is_param: bool, 31 pub(super) is_param: bool,
32 /// If a name-binding or reference to a const in a pattern. 32 /// If a name-binding or reference to a const in a pattern.
33 /// Irrefutable patterns (like let) are excluded. 33 /// Irrefutable patterns (like let) are excluded.
@@ -81,7 +81,7 @@ impl<'a> CompletionContext<'a> {
81 use_item_syntax: None, 81 use_item_syntax: None,
82 record_lit_syntax: None, 82 record_lit_syntax: None,
83 record_lit_pat: None, 83 record_lit_pat: None,
84 impl_block: None, 84 impl_def: None,
85 is_param: false, 85 is_param: false,
86 is_pat_binding: false, 86 is_pat_binding: false,
87 is_trivial_path: false, 87 is_trivial_path: false,
@@ -161,12 +161,12 @@ impl<'a> CompletionContext<'a> {
161 self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); 161 self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset);
162 } 162 }
163 163
164 self.impl_block = self 164 self.impl_def = self
165 .token 165 .token
166 .parent() 166 .parent()
167 .ancestors() 167 .ancestors()
168 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 168 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
169 .find_map(ast::ImplBlock::cast); 169 .find_map(ast::ImplDef::cast);
170 170
171 let top_node = name_ref 171 let top_node = name_ref
172 .syntax() 172 .syntax()