aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/reference_completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/reference_completion.rs')
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index f9f01a642..c578e9e8b 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -13,12 +13,12 @@ use hir::{
13 13
14use crate::{ 14use crate::{
15 db::RootDatabase, 15 db::RootDatabase,
16 completion::CompletionItem, 16 completion::{CompletionItem, Completions},
17 Cancelable 17 Cancelable
18}; 18};
19 19
20pub(super) fn completions( 20pub(super) fn completions(
21 acc: &mut Vec<CompletionItem>, 21 acc: &mut Completions,
22 db: &RootDatabase, 22 db: &RootDatabase,
23 module: &hir::Module, 23 module: &hir::Module,
24 file: &SourceFileNode, 24 file: &SourceFileNode,
@@ -117,7 +117,7 @@ fn classify_name_ref(name_ref: ast::NameRef) -> Option<NameRefKind> {
117 None 117 None
118} 118}
119 119
120fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { 120fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Completions) {
121 let mut shadowed = FxHashSet::default(); 121 let mut shadowed = FxHashSet::default();
122 scopes 122 scopes
123 .scope_chain(name_ref.syntax()) 123 .scope_chain(name_ref.syntax())
@@ -130,7 +130,7 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi
130} 130}
131 131
132fn complete_path( 132fn complete_path(
133 acc: &mut Vec<CompletionItem>, 133 acc: &mut Completions,
134 db: &RootDatabase, 134 db: &RootDatabase,
135 module: &hir::Module, 135 module: &hir::Module,
136 mut path: Path, 136 mut path: Path,
@@ -154,7 +154,7 @@ fn complete_path(
154 Ok(()) 154 Ok(())
155} 155}
156 156
157fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) { 157fn complete_mod_item_snippets(acc: &mut Completions) {
158 CompletionItem::new("Test function") 158 CompletionItem::new("Test function")
159 .lookup_by("tfn") 159 .lookup_by("tfn")
160 .snippet( 160 .snippet(
@@ -174,26 +174,26 @@ fn complete_expr_keywords(
174 file: &SourceFileNode, 174 file: &SourceFileNode,
175 fn_def: ast::FnDef, 175 fn_def: ast::FnDef,
176 name_ref: ast::NameRef, 176 name_ref: ast::NameRef,
177 acc: &mut Vec<CompletionItem>, 177 acc: &mut Completions,
178) { 178) {
179 acc.push(keyword("if", "if $0 {}")); 179 acc.add(keyword("if", "if $0 {}"));
180 acc.push(keyword("match", "match $0 {}")); 180 acc.add(keyword("match", "match $0 {}"));
181 acc.push(keyword("while", "while $0 {}")); 181 acc.add(keyword("while", "while $0 {}"));
182 acc.push(keyword("loop", "loop {$0}")); 182 acc.add(keyword("loop", "loop {$0}"));
183 183
184 if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) { 184 if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) {
185 if let Some(if_expr) = find_node_at_offset::<ast::IfExpr>(file.syntax(), off) { 185 if let Some(if_expr) = find_node_at_offset::<ast::IfExpr>(file.syntax(), off) {
186 if if_expr.syntax().range().end() < name_ref.syntax().range().start() { 186 if if_expr.syntax().range().end() < name_ref.syntax().range().start() {
187 acc.push(keyword("else", "else {$0}")); 187 acc.add(keyword("else", "else {$0}"));
188 acc.push(keyword("else if", "else if $0 {}")); 188 acc.add(keyword("else if", "else if $0 {}"));
189 } 189 }
190 } 190 }
191 } 191 }
192 if is_in_loop_body(name_ref) { 192 if is_in_loop_body(name_ref) {
193 acc.push(keyword("continue", "continue")); 193 acc.add(keyword("continue", "continue"));
194 acc.push(keyword("break", "break")); 194 acc.add(keyword("break", "break"));
195 } 195 }
196 acc.extend(complete_return(fn_def, name_ref)); 196 acc.add_all(complete_return(fn_def, name_ref));
197} 197}
198 198
199fn is_in_loop_body(name_ref: ast::NameRef) -> bool { 199fn is_in_loop_body(name_ref: ast::NameRef) -> bool {
@@ -252,7 +252,7 @@ fn keyword(kw: &str, snippet: &str) -> CompletionItem {
252 CompletionItem::new(kw).snippet(snippet).build() 252 CompletionItem::new(kw).snippet(snippet).build()
253} 253}
254 254
255fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) { 255fn complete_expr_snippets(acc: &mut Completions) {
256 CompletionItem::new("pd") 256 CompletionItem::new("pd")
257 .snippet("eprintln!(\"$0 = {:?}\", $0);") 257 .snippet("eprintln!(\"$0 = {:?}\", $0);")
258 .add_to(acc); 258 .add_to(acc);