aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock8
-rw-r--r--crates/ra_analysis/src/completion.rs2
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs5
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs84
4 files changed, 40 insertions, 59 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5e5db84c3..bf2297e69 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -734,7 +734,7 @@ dependencies = [
734 "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", 734 "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
735 "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", 735 "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
736 "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", 736 "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
737 "smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 737 "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
738 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 738 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
739 "test_utils 0.1.0", 739 "test_utils 0.1.0",
740 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 740 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -959,7 +959,7 @@ version = "0.1.3"
959source = "registry+https://github.com/rust-lang/crates.io-index" 959source = "registry+https://github.com/rust-lang/crates.io-index"
960dependencies = [ 960dependencies = [
961 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 961 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
962 "smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 962 "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
963 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 963 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
964] 964]
965 965
@@ -1092,7 +1092,7 @@ dependencies = [
1092 1092
1093[[package]] 1093[[package]]
1094name = "smol_str" 1094name = "smol_str"
1095version = "0.1.7" 1095version = "0.1.8"
1096source = "registry+https://github.com/rust-lang/crates.io-index" 1096source = "registry+https://github.com/rust-lang/crates.io-index"
1097dependencies = [ 1097dependencies = [
1098 "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", 1098 "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1565,7 +1565,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1565"checksum sha-1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9d1f3b5de8a167ab06834a7c883bd197f2191e1dda1a22d9ccfeedbf9aded" 1565"checksum sha-1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9d1f3b5de8a167ab06834a7c883bd197f2191e1dda1a22d9ccfeedbf9aded"
1566"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" 1566"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
1567"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" 1567"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db"
1568"checksum smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ed6f19b800d76574926e458d5f8e2dbea86c2b58c08d33a982448f09ac8d0c" 1568"checksum smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "486a74e9b9fc53373808f7a17e10fc728adcb1fbe272292271d8bea61175e181"
1569"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" 1569"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
1570"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" 1570"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
1571"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" 1571"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index 6d84558d1..fd7b78c2a 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -428,7 +428,7 @@ mod tests {
428 <|> 428 <|>
429 } 429 }
430 ", 430 ",
431 r##"[CompletionItem { label: "Test function", lookup: Some("tfn"), snippet: Some("#[test]\nfn ${1:feature}() {\n$0\n}") }, 431 r##"[CompletionItem { label: "Test function", lookup: Some("tfn"), snippet: Some("#[test]\nfn ${1:feature}() {\n $0\n}") },
432 CompletionItem { label: "pub(crate)", lookup: None, snippet: Some("pub(crate) $0") }]"##, 432 CompletionItem { label: "pub(crate)", lookup: None, snippet: Some("pub(crate) $0") }]"##,
433 ); 433 );
434 } 434 }
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 309b0108d..7edb86436 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -19,6 +19,7 @@ impl CompletionItem {
19 } 19 }
20} 20}
21 21
22#[must_use]
22pub(crate) struct Builder { 23pub(crate) struct Builder {
23 label: String, 24 label: String,
24 lookup: Option<String>, 25 lookup: Option<String>,
@@ -41,4 +42,8 @@ impl Builder {
41 self.lookup = Some(lookup.into()); 42 self.lookup = Some(lookup.into());
42 self 43 self
43 } 44 }
45 pub fn snippet(mut self, snippet: impl Into<String>) -> Builder {
46 self.snippet = Some(snippet.into());
47 self
48 }
44} 49}
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index 457ca13cc..23052295c 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -125,23 +125,13 @@ fn classify_name_ref(name_ref: ast::NameRef) -> Option<NameRefKind> {
125 125
126fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { 126fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
127 let mut shadowed = FxHashSet::default(); 127 let mut shadowed = FxHashSet::default();
128 acc.extend( 128 scopes
129 scopes 129 .scope_chain(name_ref.syntax())
130 .scope_chain(name_ref.syntax()) 130 .flat_map(|scope| scopes.entries(scope).iter())
131 .flat_map(|scope| scopes.entries(scope).iter()) 131 .filter(|entry| shadowed.insert(entry.name()))
132 .filter(|entry| shadowed.insert(entry.name())) 132 .for_each(|entry| CompletionItem::new(entry.name().to_string()).add_to(acc));
133 .map(|entry| CompletionItem {
134 label: entry.name().to_string(),
135 lookup: None,
136 snippet: None,
137 }),
138 );
139 if scopes.self_param.is_some() { 133 if scopes.self_param.is_some() {
140 acc.push(CompletionItem { 134 CompletionItem::new("self").add_to(acc);
141 label: "self".to_string(),
142 lookup: None,
143 snippet: None,
144 })
145 } 135 }
146} 136}
147 137
@@ -164,32 +154,26 @@ fn complete_path(
164 _ => return Ok(()), 154 _ => return Ok(()),
165 }; 155 };
166 let module_scope = target_module.scope(db)?; 156 let module_scope = target_module.scope(db)?;
167 let completions = module_scope.entries().map(|(name, _res)| CompletionItem { 157 module_scope
168 label: name.to_string(), 158 .entries()
169 lookup: None, 159 .for_each(|(name, _res)| CompletionItem::new(name.to_string()).add_to(acc));
170 snippet: None,
171 });
172 acc.extend(completions);
173 Ok(()) 160 Ok(())
174} 161}
175 162
176fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) { 163fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
177 acc.push(CompletionItem { 164 CompletionItem::new("Test function")
178 label: "Test function".to_string(), 165 .lookup_by("tfn")
179 lookup: Some("tfn".to_string()), 166 .snippet(
180 snippet: Some( 167 "\
181 "#[test]\n\ 168#[test]
182 fn ${1:feature}() {\n\ 169fn ${1:feature}() {
183 $0\n\ 170 $0
184 }" 171}",
185 .to_string(), 172 )
186 ), 173 .add_to(acc);
187 }); 174 CompletionItem::new("pub(crate)")
188 acc.push(CompletionItem { 175 .snippet("pub(crate) $0")
189 label: "pub(crate)".to_string(), 176 .add_to(acc);
190 lookup: None,
191 snippet: Some("pub(crate) $0".to_string()),
192 })
193} 177}
194 178
195fn complete_expr_keywords( 179fn complete_expr_keywords(
@@ -270,23 +254,15 @@ fn complete_return(fn_def: ast::FnDef, name_ref: ast::NameRef) -> Option<Complet
270 Some(keyword("return", snip)) 254 Some(keyword("return", snip))
271} 255}
272 256
273fn keyword(kw: &str, snip: &str) -> CompletionItem { 257fn keyword(kw: &str, snippet: &str) -> CompletionItem {
274 CompletionItem { 258 CompletionItem::new(kw).snippet(snippet).build()
275 label: kw.to_string(),
276 lookup: None,
277 snippet: Some(snip.to_string()),
278 }
279} 259}
280 260
281fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) { 261fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) {
282 acc.push(CompletionItem { 262 CompletionItem::new("pd")
283 label: "pd".to_string(), 263 .snippet("eprintln!(\"$0 = {:?}\", $0);")
284 lookup: None, 264 .add_to(acc);
285 snippet: Some("eprintln!(\"$0 = {:?}\", $0);".to_string()), 265 CompletionItem::new("ppd")
286 }); 266 .snippet("eprintln!(\"$0 = {:#?}\", $0);")
287 acc.push(CompletionItem { 267 .add_to(acc);
288 label: "ppd".to_string(),
289 lookup: None,
290 snippet: Some("eprintln!(\"$0 = {:#?}\", $0);".to_string()),
291 });
292} 268}