aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 08:47:28 +0000
committerAleksey Kladov <[email protected]>2019-01-08 08:47:28 +0000
commit3ffd5dd2a63e8efe182e79439a879ec1f9420b77 (patch)
tree5a674d9b89081a371f07b5a0c0a21f0b71d7e75a /crates/ra_analysis/src/completion
parentda0b348ae9f629c5cbe4a836a90ed85e36ca18e5 (diff)
migrate ra_analysis to new rowan
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r--crates/ra_analysis/src/completion/complete_fn_param.rs6
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs6
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs29
3 files changed, 17 insertions, 24 deletions
diff --git a/crates/ra_analysis/src/completion/complete_fn_param.rs b/crates/ra_analysis/src/completion/complete_fn_param.rs
index bb5fdfda0..c1739e47e 100644
--- a/crates/ra_analysis/src/completion/complete_fn_param.rs
+++ b/crates/ra_analysis/src/completion/complete_fn_param.rs
@@ -39,9 +39,9 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
39 .add_to(acc) 39 .add_to(acc)
40 }); 40 });
41 41
42 fn process<'a, N: ast::FnDefOwner<'a>>( 42 fn process<'a, N: ast::FnDefOwner>(
43 node: N, 43 node: &'a N,
44 params: &mut FxHashMap<String, (u32, ast::Param<'a>)>, 44 params: &mut FxHashMap<String, (u32, &'a ast::Param)>,
45 ) { 45 ) {
46 node.functions() 46 node.functions()
47 .filter_map(|it| it.param_list()) 47 .filter_map(|it| it.param_list())
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs
index 28194c908..d350f06ce 100644
--- a/crates/ra_analysis/src/completion/complete_keyword.rs
+++ b/crates/ra_analysis/src/completion/complete_keyword.rs
@@ -2,7 +2,7 @@ use ra_syntax::{
2 algo::visit::{visitor, Visitor}, 2 algo::visit::{visitor, Visitor},
3 AstNode, 3 AstNode,
4 ast::{self, LoopBodyOwner}, 4 ast::{self, LoopBodyOwner},
5 SyntaxKind::*, SyntaxNodeRef, 5 SyntaxKind::*, SyntaxNode,
6}; 6};
7 7
8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; 8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
@@ -76,7 +76,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
76 acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); 76 acc.add_all(complete_return(fn_def, ctx.can_be_stmt));
77} 77}
78 78
79fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { 79fn is_in_loop_body(leaf: &SyntaxNode) -> bool {
80 for node in leaf.ancestors() { 80 for node in leaf.ancestors() {
81 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { 81 if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
82 break; 82 break;
@@ -95,7 +95,7 @@ fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool {
95 false 95 false
96} 96}
97 97
98fn complete_return(fn_def: ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { 98fn complete_return(fn_def: &ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> {
99 let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { 99 let snip = match (can_be_stmt, fn_def.ret_type().is_some()) {
100 (true, true) => "return $0;", 100 (true, true) => "return $0;",
101 (true, false) => "return;", 101 (true, false) => "return;",
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 4584f355d..988c21c58 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -1,13 +1,9 @@
1use ra_editor::find_node_at_offset; 1use ra_editor::find_node_at_offset;
2use ra_text_edit::AtomTextEdit; 2use ra_text_edit::AtomTextEdit;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{find_leaf_at_offset, find_covering_node}, 4 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange,
5 ast, 5 ast,
6 AstNode, 6 algo::{find_leaf_at_offset, find_covering_node},
7 SyntaxNodeRef,
8 SourceFileNode,
9 TextUnit,
10 TextRange,
11 SyntaxKind::*, 7 SyntaxKind::*,
12}; 8};
13use hir::source_binder; 9use hir::source_binder;
@@ -20,11 +16,11 @@ use crate::{db, FilePosition, Cancelable};
20pub(super) struct CompletionContext<'a> { 16pub(super) struct CompletionContext<'a> {
21 pub(super) db: &'a db::RootDatabase, 17 pub(super) db: &'a db::RootDatabase,
22 pub(super) offset: TextUnit, 18 pub(super) offset: TextUnit,
23 pub(super) leaf: SyntaxNodeRef<'a>, 19 pub(super) leaf: &'a SyntaxNode,
24 pub(super) module: Option<hir::Module>, 20 pub(super) module: Option<hir::Module>,
25 pub(super) function: Option<hir::Function>, 21 pub(super) function: Option<hir::Function>,
26 pub(super) function_syntax: Option<ast::FnDef<'a>>, 22 pub(super) function_syntax: Option<&'a ast::FnDef>,
27 pub(super) use_item_syntax: Option<ast::UseItem<'a>>, 23 pub(super) use_item_syntax: Option<&'a ast::UseItem>,
28 pub(super) is_param: bool, 24 pub(super) is_param: bool,
29 /// A single-indent path, like `foo`. 25 /// A single-indent path, like `foo`.
30 pub(super) is_trivial_path: bool, 26 pub(super) is_trivial_path: bool,
@@ -36,7 +32,7 @@ pub(super) struct CompletionContext<'a> {
36 /// Something is typed at the "top" level, in module or impl/trait. 32 /// Something is typed at the "top" level, in module or impl/trait.
37 pub(super) is_new_item: bool, 33 pub(super) is_new_item: bool,
38 /// The receiver if this is a field or method access, i.e. writing something.<|> 34 /// The receiver if this is a field or method access, i.e. writing something.<|>
39 pub(super) dot_receiver: Option<ast::Expr<'a>>, 35 pub(super) dot_receiver: Option<&'a ast::Expr>,
40 /// If this is a method call in particular, i.e. the () are already there. 36 /// If this is a method call in particular, i.e. the () are already there.
41 pub(super) is_method_call: bool, 37 pub(super) is_method_call: bool,
42} 38}
@@ -44,7 +40,7 @@ pub(super) struct CompletionContext<'a> {
44impl<'a> CompletionContext<'a> { 40impl<'a> CompletionContext<'a> {
45 pub(super) fn new( 41 pub(super) fn new(
46 db: &'a db::RootDatabase, 42 db: &'a db::RootDatabase,
47 original_file: &'a SourceFileNode, 43 original_file: &'a SourceFile,
48 position: FilePosition, 44 position: FilePosition,
49 ) -> Cancelable<Option<CompletionContext<'a>>> { 45 ) -> Cancelable<Option<CompletionContext<'a>>> {
50 let module = source_binder::module_from_position(db, position)?; 46 let module = source_binder::module_from_position(db, position)?;
@@ -71,7 +67,7 @@ impl<'a> CompletionContext<'a> {
71 Ok(Some(ctx)) 67 Ok(Some(ctx))
72 } 68 }
73 69
74 fn fill(&mut self, original_file: &'a SourceFileNode, offset: TextUnit) { 70 fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) {
75 // Insert a fake ident to get a valid parse tree. We will use this file 71 // Insert a fake ident to get a valid parse tree. We will use this file
76 // to determine context, though the original_file will be used for 72 // to determine context, though the original_file will be used for
77 // actual completion. 73 // actual completion.
@@ -100,7 +96,7 @@ impl<'a> CompletionContext<'a> {
100 } 96 }
101 } 97 }
102 } 98 }
103 fn classify_name_ref(&mut self, original_file: &'a SourceFileNode, name_ref: ast::NameRef) { 99 fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) {
104 let name_range = name_ref.syntax().range(); 100 let name_range = name_ref.syntax().range();
105 let top_node = name_ref 101 let top_node = name_ref
106 .syntax() 102 .syntax()
@@ -197,15 +193,12 @@ impl<'a> CompletionContext<'a> {
197 } 193 }
198} 194}
199 195
200fn find_node_with_range<'a, N: AstNode<'a>>( 196fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<&N> {
201 syntax: SyntaxNodeRef<'a>,
202 range: TextRange,
203) -> Option<N> {
204 let node = find_covering_node(syntax, range); 197 let node = find_covering_node(syntax, range);
205 node.ancestors().find_map(N::cast) 198 node.ancestors().find_map(N::cast)
206} 199}
207 200
208fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { 201fn is_node<N: AstNode>(node: &SyntaxNode) -> bool {
209 match node.ancestors().filter_map(N::cast).next() { 202 match node.ancestors().filter_map(N::cast).next() {
210 None => false, 203 None => false,
211 Some(n) => n.syntax().range() == node.range(), 204 Some(n) => n.syntax().range() == node.range(),