diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-09 22:47:34 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-09 22:47:34 +0100 |
commit | 176f7f61175bc433c56083a758bd7a28a8ae31f8 (patch) | |
tree | cca4821454502279317323fbc63dccdb9c68c5b9 /crates/ra_ide/src/completion | |
parent | eb07803e8106a66edfd80d078337dae240e92828 (diff) | |
parent | 30084a56a5731343bd4cec727646a6c55900234f (diff) |
Merge #3923
3923: Cleanup keyword accessors r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_fn_param.rs | 30 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 4 |
2 files changed, 18 insertions, 16 deletions
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 62ae5ccb4..f84b559fc 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs | |||
@@ -1,6 +1,9 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_syntax::{ast, match_ast, AstNode}; | 3 | use ra_syntax::{ |
4 | ast::{self, ModuleItemOwner}, | ||
5 | match_ast, AstNode, | ||
6 | }; | ||
4 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
5 | 8 | ||
6 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; | 9 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; |
@@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
16 | 19 | ||
17 | let mut params = FxHashMap::default(); | 20 | let mut params = FxHashMap::default(); |
18 | for node in ctx.token.parent().ancestors() { | 21 | for node in ctx.token.parent().ancestors() { |
19 | match_ast! { | 22 | let items = match_ast! { |
20 | match node { | 23 | match node { |
21 | ast::SourceFile(it) => process(it, &mut params), | 24 | ast::SourceFile(it) => it.items(), |
22 | ast::ItemList(it) => process(it, &mut params), | 25 | ast::ItemList(it) => it.items(), |
23 | _ => (), | 26 | _ => continue, |
27 | } | ||
28 | }; | ||
29 | for item in items { | ||
30 | if let ast::ModuleItem::FnDef(func) = item { | ||
31 | func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { | ||
32 | let text = param.syntax().text().to_string(); | ||
33 | params.entry(text).or_insert((0, param)).0 += 1; | ||
34 | }) | ||
24 | } | 35 | } |
25 | } | 36 | } |
26 | } | 37 | } |
@@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
39 | .lookup_by(lookup) | 50 | .lookup_by(lookup) |
40 | .add_to(acc) | 51 | .add_to(acc) |
41 | }); | 52 | }); |
42 | |||
43 | fn process<N: ast::FnDefOwner>(node: N, params: &mut FxHashMap<String, (u32, ast::Param)>) { | ||
44 | node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each( | ||
45 | |param| { | ||
46 | let text = param.syntax().text().to_string(); | ||
47 | params.entry(text).or_insert((0, param)).0 += 1; | ||
48 | }, | ||
49 | ) | ||
50 | } | ||
51 | } | 53 | } |
52 | 54 | ||
53 | #[cfg(test)] | 55 | #[cfg(test)] |
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 0e34d85db..6637afaf7 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -191,8 +191,8 @@ impl<'a> CompletionContext<'a> { | |||
191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { | 191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { |
192 | self.is_pat_binding_or_const = true; | 192 | self.is_pat_binding_or_const = true; |
193 | if bind_pat.at_token().is_some() | 193 | if bind_pat.at_token().is_some() |
194 | || bind_pat.ref_kw_token().is_some() | 194 | || bind_pat.ref_token().is_some() |
195 | || bind_pat.mut_kw_token().is_some() | 195 | || bind_pat.mut_token().is_some() |
196 | { | 196 | { |
197 | self.is_pat_binding_or_const = false; | 197 | self.is_pat_binding_or_const = false; |
198 | } | 198 | } |