diff options
author | Kevin DeLorey <[email protected]> | 2020-02-08 19:22:31 +0000 |
---|---|---|
committer | Kevin DeLorey <[email protected]> | 2020-02-08 19:22:31 +0000 |
commit | 5c0c18926b13d40cff722f603ed8f58550dbbc59 (patch) | |
tree | 518e7fdf612788af5078255594e6b9338be7eb39 /crates/ra_ide/src/completion | |
parent | f801723dd2e4a518c1608909509f47f03d75fe1a (diff) |
Cleaning up unessicary code that the Magic completion takes care of.
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 7af485cdd..d147bd11d 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionKind, CompletionItemKind}; | 1 | use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionKind, CompletionItemKind}; |
2 | 2 | ||
3 | use ast::{ NameOwner }; | 3 | use ra_syntax::ast::{self, NameOwner, AstNode}; |
4 | use hir::{ self, db::HirDatabase }; | 4 | |
5 | use hir::{self, db::HirDatabase}; | ||
5 | 6 | ||
6 | use ra_syntax::{ SyntaxKind, ast, ast::AstNode, TextRange }; | ||
7 | 7 | ||
8 | pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { | 8 | pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { |
9 | let impl_block = ctx.impl_block.as_ref(); | 9 | let impl_block = ctx.impl_block.as_ref(); |
@@ -23,40 +23,9 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | 25 | ||
26 | // for cases where the user has already started writing the function def, navigate | 26 | let target_trait = target_trait.unwrap(); |
27 | // the previous tokens in order to find the location of that token so that we may | ||
28 | // replace it with our completion. | ||
29 | let start_position = { | ||
30 | let mut prev_token = ctx.token | ||
31 | .prev_token() | ||
32 | .clone(); | ||
33 | |||
34 | while let Some(token) = &prev_token { | ||
35 | match token.kind() { | ||
36 | SyntaxKind::FN_KW => break, | ||
37 | |||
38 | // todo: attempt to find a better way of determining when to stop as | ||
39 | // the following feels sketchy. | ||
40 | SyntaxKind::IMPL_KW | | ||
41 | SyntaxKind::L_CURLY | | ||
42 | SyntaxKind::R_CURLY => { | ||
43 | prev_token = None; | ||
44 | break; | ||
45 | } | ||
46 | _ => {} | ||
47 | } | ||
48 | |||
49 | prev_token = token.prev_token().clone(); | ||
50 | } | ||
51 | |||
52 | prev_token | ||
53 | .map(|t| t.text_range()) | ||
54 | .unwrap_or(ctx.source_range()) | ||
55 | }; | ||
56 | |||
57 | let trait_ = target_trait.unwrap(); | ||
58 | 27 | ||
59 | let trait_items = trait_.items(ctx.db); | 28 | let trait_items = target_trait.items(ctx.db); |
60 | let missing_items = trait_items | 29 | let missing_items = trait_items |
61 | .iter() | 30 | .iter() |
62 | .filter(|i| { | 31 | .filter(|i| { |
@@ -127,7 +96,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
127 | 96 | ||
128 | for item in missing_items { | 97 | for item in missing_items { |
129 | match item { | 98 | match item { |
130 | hir::AssocItem::Function(f) => add_function_impl(acc, ctx, f, start_position), | 99 | hir::AssocItem::Function(f) => add_function_impl(acc, ctx, f), |
131 | _ => {} | 100 | _ => {} |
132 | } | 101 | } |
133 | } | 102 | } |
@@ -152,7 +121,7 @@ fn resolve_target_trait( | |||
152 | } | 121 | } |
153 | } | 122 | } |
154 | 123 | ||
155 | pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function, start: TextRange) { | 124 | pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function) { |
156 | use crate::display::FunctionSignature; | 125 | use crate::display::FunctionSignature; |
157 | 126 | ||
158 | let display = FunctionSignature::from_hir(ctx.db, func.clone()); | 127 | let display = FunctionSignature::from_hir(ctx.db, func.clone()); |
@@ -165,7 +134,7 @@ pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, | |||
165 | format!("fn {}()", func_name.to_string()) | 134 | format!("fn {}()", func_name.to_string()) |
166 | }; | 135 | }; |
167 | 136 | ||
168 | let builder = CompletionItem::new(CompletionKind::Magic, start, label.clone()) | 137 | let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone()) |
169 | .lookup_by(label); | 138 | .lookup_by(label); |
170 | 139 | ||
171 | let completion_kind = if func.has_self_param(ctx.db) { | 140 | let completion_kind = if func.has_self_param(ctx.db) { |