aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_scope.rs63
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs11
2 files changed, 16 insertions, 58 deletions
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs
index 82842e7e3..6b0621081 100644
--- a/crates/ra_ide/src/completion/complete_scope.rs
+++ b/crates/ra_ide/src/completion/complete_scope.rs
@@ -1,13 +1,17 @@
1//! Completion of names from the current scope, e.g. locals and imported items. 1//! Completion of names from the current scope, e.g. locals and imported items.
2 2
3use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
4use hir::ScopeDef;
4 5
5pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { 6pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
6 if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path { 7 if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path {
7 return; 8 return;
8 } 9 }
9 10
10 ctx.scope().process_all_names(&mut |name, res| acc.add_resolution(ctx, name.to_string(), &res)); 11 ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) {
12 (true, ScopeDef::Local(..)) => {}
13 _ => acc.add_resolution(ctx, name.to_string(), &res),
14 });
11} 15}
12 16
13#[cfg(test)] 17#[cfg(test)]
@@ -21,53 +25,23 @@ mod tests {
21 } 25 }
22 26
23 #[test] 27 #[test]
24 fn nested_bind_pat_and_path() { 28 fn bind_pat_and_path_ignore_ref() {
25 assert_debug_snapshot!( 29 assert_debug_snapshot!(
26 do_reference_completion( 30 do_reference_completion(
27 r" 31 r"
28 enum First { 32 enum Enum {
29 A, 33 A,
30 B, 34 B,
31 } 35 }
32 enum Second { 36 fn quux(x: Option<Enum>) {
33 A(First),
34 B(First),
35 }
36 fn quux(x: Option<Option<Second>>>) {
37 match x { 37 match x {
38 None => (), 38 None => (),
39 Some(Some(Second(Fi<|>))) => (), 39 Some(ref en<|>) => (),
40 } 40 }
41 } 41 }
42 " 42 "
43 ), 43 ),
44 @r###" 44 @r###"[]"###
45 [
46 CompletionItem {
47 label: "First",
48 source_range: [363; 365),
49 delete: [363; 365),
50 insert: "First",
51 kind: Enum,
52 },
53 CompletionItem {
54 label: "Second",
55 source_range: [363; 365),
56 delete: [363; 365),
57 insert: "Second",
58 kind: Enum,
59 },
60 CompletionItem {
61 label: "quux(…)",
62 source_range: [363; 365),
63 delete: [363; 365),
64 insert: "quux(${1:x})$0",
65 kind: Function,
66 lookup: "quux",
67 detail: "fn quux(x: Option<Option<Second>>)",
68 },
69 ]
70 "###
71 ); 45 );
72 } 46 }
73 47
@@ -83,7 +57,7 @@ mod tests {
83 fn quux(x: Option<Enum>) { 57 fn quux(x: Option<Enum>) {
84 match x { 58 match x {
85 None => (), 59 None => (),
86 Some(en<|>) => (), 60 Some(En<|>) => (),
87 } 61 }
88 } 62 }
89 " 63 "
@@ -98,13 +72,6 @@ mod tests {
98 kind: Enum, 72 kind: Enum,
99 }, 73 },
100 CompletionItem { 74 CompletionItem {
101 label: "None",
102 source_range: [231; 233),
103 delete: [231; 233),
104 insert: "None",
105 kind: Binding,
106 },
107 CompletionItem {
108 label: "quux(…)", 75 label: "quux(…)",
109 source_range: [231; 233), 76 source_range: [231; 233),
110 delete: [231; 233), 77 delete: [231; 233),
@@ -112,13 +79,7 @@ mod tests {
112 kind: Function, 79 kind: Function,
113 lookup: "quux", 80 lookup: "quux",
114 detail: "fn quux(x: Option<Enum>)", 81 detail: "fn quux(x: Option<Enum>)",
115 }, 82 trigger_call_info: true,
116 CompletionItem {
117 label: "x",
118 source_range: [231; 233),
119 delete: [231; 233),
120 insert: "x",
121 kind: Binding,
122 }, 83 },
123 ] 84 ]
124 "### 85 "###
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index d867ff6b2..f9d4154d8 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -190,19 +190,16 @@ impl<'a> CompletionContext<'a> {
190 // suggest declaration names, see `CompletionKind::Magic`. 190 // suggest declaration names, see `CompletionKind::Magic`.
191 if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { 191 if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) {
192 if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { 192 if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) {
193 let mut parent = bind_pat.syntax().parent(); 193 let parent = bind_pat.syntax().parent();
194 if parent.clone().and_then(ast::MatchArm::cast).is_some() 194 if parent.clone().and_then(ast::MatchArm::cast).is_some()
195 || parent.clone().and_then(ast::Condition::cast).is_some() 195 || parent.clone().and_then(ast::Condition::cast).is_some()
196 { 196 {
197 self.is_pat_binding = true; 197 self.is_pat_binding = true;
198 } 198 }
199 199
200 while let Some(_) = parent.clone().and_then(ast::TupleStructPat::cast) { 200 let bind_pat_string = bind_pat.syntax().to_string();
201 parent = parent.and_then(|p| p.parent()); 201 if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
202 if parent.clone().and_then(ast::MatchArm::cast).is_some() { 202 self.is_pat_binding_and_path = true;
203 self.is_pat_binding_and_path = true;
204 break;
205 }
206 } 203 }
207 } 204 }
208 if is_node::<ast::Param>(name.syntax()) { 205 if is_node::<ast::Param>(name.syntax()) {