aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/completion.rs32
-rw-r--r--crates/ra_editor/src/extend_selection.rs16
-rw-r--r--crates/ra_editor/src/scope/fn_scope.rs9
3 files changed, 53 insertions, 4 deletions
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs
index 62a63fb04..570d72d66 100644
--- a/crates/ra_editor/src/completion.rs
+++ b/crates/ra_editor/src/completion.rs
@@ -39,6 +39,12 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI
39 if is_node::<ast::Param>(name_ref.syntax()) { 39 if is_node::<ast::Param>(name_ref.syntax()) {
40 param_completions(name_ref.syntax(), &mut res); 40 param_completions(name_ref.syntax(), &mut res);
41 } 41 }
42 let name_range = name_ref.syntax().range();
43 let top_node = name_ref.syntax().ancestors().take_while(|it| it.range() == name_range).last().unwrap();
44 match top_node.parent().map(|it| it.kind()) {
45 Some(ROOT) | Some(ITEM_LIST) => complete_mod_item_snippets(&mut res),
46 _ => (),
47 }
42 } 48 }
43 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) { 49 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) {
44 if is_node::<ast::Param>(name.syntax()) { 50 if is_node::<ast::Param>(name.syntax()) {
@@ -216,6 +222,15 @@ fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) {
216 ); 222 );
217} 223}
218 224
225fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
226 acc.push(CompletionItem {
227 label: "tfn".to_string(),
228 lookup: None,
229 snippet: Some("#[test]\nfn $1() {\n $0\n}".to_string()),
230 }
231 );
232}
233
219fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { 234fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
220 let mut shadowed = HashSet::new(); 235 let mut shadowed = HashSet::new();
221 acc.extend( 236 acc.extend(
@@ -506,4 +521,21 @@ mod tests {
506 CompletionItem { label: "SourceRoot", lookup: None, snippet: None }, 521 CompletionItem { label: "SourceRoot", lookup: None, snippet: None },
507 CompletionItem { label: "file_id: FileId", lookup: Some("file_id"), snippet: None }]"#); 522 CompletionItem { label: "file_id: FileId", lookup: Some("file_id"), snippet: None }]"#);
508 } 523 }
524
525 #[test]
526 fn test_tfn_snippet() {
527 // check_snippet_completion(r"
528 // <|>
529 // ",
530 // r##"[CompletionItem { label: "tfn", lookup: None, snippet: Some("#[test]\nfn $1() {\n $0\n}") }]"##,
531 // );
532 check_snippet_completion(r"
533 #[cfg(test)]
534 mod tests {
535 <|>
536 }
537 ",
538 r##"[CompletionItem { label: "tfn", lookup: None, snippet: Some("#[test]\nfn $1() {\n $0\n}") }]"##,
539 );
540 }
509} 541}
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 6977900e6..e12346cb6 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -154,6 +154,22 @@ impl S {
154 } 154 }
155 155
156 #[test] 156 #[test]
157 fn test_extend_selection_doc_comments() {
158 do_check(
159 r#"
160struct A;
161
162/// bla
163/// bla
164struct B {
165 <|>
166}
167 "#,
168 &["\n \n", "{\n \n}", "/// bla\n/// bla\nstruct B {\n \n}"]
169 )
170 }
171
172 #[test]
157 fn test_extend_selection_comments() { 173 fn test_extend_selection_comments() {
158 do_check( 174 do_check(
159 r#" 175 r#"
diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs
index a99bd1822..65d85279f 100644
--- a/crates/ra_editor/src/scope/fn_scope.rs
+++ b/crates/ra_editor/src/scope/fn_scope.rs
@@ -245,11 +245,13 @@ pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> O
245 use std::collections::HashSet; 245 use std::collections::HashSet;
246 246
247 let mut shadowed = HashSet::new(); 247 let mut shadowed = HashSet::new();
248 scopes.scope_chain(name_ref.syntax()) 248 let ret = scopes.scope_chain(name_ref.syntax())
249 .flat_map(|scope| scopes.entries(scope).iter()) 249 .flat_map(|scope| scopes.entries(scope).iter())
250 .filter(|entry| shadowed.insert(entry.name())) 250 .filter(|entry| shadowed.insert(entry.name()))
251 .filter(|entry| entry.name() == name_ref.text()) 251 .filter(|entry| entry.name() == name_ref.text())
252 .nth(0) 252 .nth(0);
253 eprintln!("ret = {:?}", ret);
254 ret
253} 255}
254 256
255#[cfg(test)] 257#[cfg(test)]
@@ -357,7 +359,6 @@ mod tests {
357 let scopes = FnScopes::new(fn_def); 359 let scopes = FnScopes::new(fn_def);
358 360
359 let local_name = resolve_local_name(name_ref, &scopes).unwrap().ast().name().unwrap(); 361 let local_name = resolve_local_name(name_ref, &scopes).unwrap().ast().name().unwrap();
360
361 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()).unwrap(); 362 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()).unwrap();
362 assert_eq!(local_name.syntax().range(), expected_name.syntax().range()); 363 assert_eq!(local_name.syntax().range(), expected_name.syntax().range());
363 } 364 }
@@ -394,4 +395,4 @@ mod tests {
394 }", 395 }",
395 46); 396 46);
396 } 397 }
397} \ No newline at end of file 398}