aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-21 17:55:00 +0000
committerAleksey Kladov <[email protected]>2018-12-21 17:55:00 +0000
commitcbe67339df2bbcb17e12ad74e8b8cd53baffb9f7 (patch)
tree633f0e84927f8747b1349ac345e606654cb7a572 /crates/ra_analysis/src/completion.rs
parentc2bf174e9c3f994d83e7e72b6e15c9b26c5b31a2 (diff)
more completion components
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r--crates/ra_analysis/src/completion.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index 39066d51f..883b3e851 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -2,7 +2,8 @@ mod completion_item;
2mod reference_completion; 2mod reference_completion;
3 3
4mod complete_fn_param; 4mod complete_fn_param;
5mod complete_keywords; 5mod complete_keyword;
6mod complete_snippet;
6 7
7use ra_editor::find_node_at_offset; 8use ra_editor::find_node_at_offset;
8use ra_text_edit::AtomTextEdit; 9use ra_text_edit::AtomTextEdit;
@@ -49,7 +50,9 @@ pub(crate) fn completions(
49 50
50 let ctx = ctry!(SyntaxContext::new(&original_file, position.offset)); 51 let ctx = ctry!(SyntaxContext::new(&original_file, position.offset));
51 complete_fn_param::complete_fn_param(&mut acc, &ctx); 52 complete_fn_param::complete_fn_param(&mut acc, &ctx);
52 complete_keywords::complete_expr_keyword(&mut acc, &ctx); 53 complete_keyword::complete_expr_keyword(&mut acc, &ctx);
54 complete_snippet::complete_expr_snippet(&mut acc, &ctx);
55 complete_snippet::complete_item_snippet(&mut acc, &ctx);
53 56
54 Ok(Some(acc)) 57 Ok(Some(acc))
55} 58}
@@ -61,10 +64,12 @@ pub(super) struct SyntaxContext<'a> {
61 leaf: SyntaxNodeRef<'a>, 64 leaf: SyntaxNodeRef<'a>,
62 enclosing_fn: Option<ast::FnDef<'a>>, 65 enclosing_fn: Option<ast::FnDef<'a>>,
63 is_param: bool, 66 is_param: bool,
64 /// a single-indent path, like `foo`. 67 /// A single-indent path, like `foo`.
65 is_trivial_path: bool, 68 is_trivial_path: bool,
66 after_if: bool, 69 after_if: bool,
67 is_stmt: bool, 70 is_stmt: bool,
71 /// Something is typed at the "top" level, in module or impl/trait.
72 is_new_item: bool,
68} 73}
69 74
70impl SyntaxContext<'_> { 75impl SyntaxContext<'_> {
@@ -77,6 +82,7 @@ impl SyntaxContext<'_> {
77 is_trivial_path: false, 82 is_trivial_path: false,
78 after_if: false, 83 after_if: false,
79 is_stmt: false, 84 is_stmt: false,
85 is_new_item: false,
80 }; 86 };
81 ctx.fill(original_file, offset); 87 ctx.fill(original_file, offset);
82 Some(ctx) 88 Some(ctx)
@@ -112,17 +118,22 @@ impl SyntaxContext<'_> {
112 } 118 }
113 } 119 }
114 fn classify_name_ref(&mut self, file: &SourceFileNode, name_ref: ast::NameRef) { 120 fn classify_name_ref(&mut self, file: &SourceFileNode, name_ref: ast::NameRef) {
115 // let name_range = name_ref.syntax().range(); 121 let name_range = name_ref.syntax().range();
116 // let top_node = name_ref 122 let top_node = name_ref
117 // .syntax() 123 .syntax()
118 // .ancestors() 124 .ancestors()
119 // .take_while(|it| it.range() == name_range) 125 .take_while(|it| it.range() == name_range)
120 // .last() 126 .last()
121 // .unwrap(); 127 .unwrap();
122 // match top_node.parent().map(|it| it.kind()) { 128
123 // Some(SOURCE_FILE) | Some(ITEM_LIST) => return Some(NameRefKind::BareIdentInMod), 129 match top_node.parent().map(|it| it.kind()) {
124 // _ => (), 130 Some(SOURCE_FILE) | Some(ITEM_LIST) => {
125 // } 131 self.is_new_item = true;
132 return;
133 }
134 _ => (),
135 }
136
126 let parent = match name_ref.syntax().parent() { 137 let parent = match name_ref.syntax().parent() {
127 Some(it) => it, 138 Some(it) => it,
128 None => return, 139 None => return,