From 3ffd5dd2a63e8efe182e79439a879ec1f9420b77 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 11:47:28 +0300 Subject: migrate ra_analysis to new rowan --- .../src/completion/complete_fn_param.rs | 6 ++--- .../ra_analysis/src/completion/complete_keyword.rs | 6 ++--- .../src/completion/completion_context.rs | 29 ++++++++-------------- 3 files changed, 17 insertions(+), 24 deletions(-) (limited to 'crates/ra_analysis/src/completion') 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) .add_to(acc) }); - fn process<'a, N: ast::FnDefOwner<'a>>( - node: N, - params: &mut FxHashMap)>, + fn process<'a, N: ast::FnDefOwner>( + node: &'a N, + params: &mut FxHashMap, ) { node.functions() .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::{ algo::visit::{visitor, Visitor}, AstNode, ast::{self, LoopBodyOwner}, - SyntaxKind::*, SyntaxNodeRef, + SyntaxKind::*, SyntaxNode, }; use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; @@ -76,7 +76,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); } -fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { +fn is_in_loop_body(leaf: &SyntaxNode) -> bool { for node in leaf.ancestors() { if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { break; @@ -95,7 +95,7 @@ fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { false } -fn complete_return(fn_def: ast::FnDef, can_be_stmt: bool) -> Option { +fn complete_return(fn_def: &ast::FnDef, can_be_stmt: bool) -> Option { let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { (true, true) => "return $0;", (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 @@ use ra_editor::find_node_at_offset; use ra_text_edit::AtomTextEdit; use ra_syntax::{ - algo::{find_leaf_at_offset, find_covering_node}, + AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, ast, - AstNode, - SyntaxNodeRef, - SourceFileNode, - TextUnit, - TextRange, + algo::{find_leaf_at_offset, find_covering_node}, SyntaxKind::*, }; use hir::source_binder; @@ -20,11 +16,11 @@ use crate::{db, FilePosition, Cancelable}; pub(super) struct CompletionContext<'a> { pub(super) db: &'a db::RootDatabase, pub(super) offset: TextUnit, - pub(super) leaf: SyntaxNodeRef<'a>, + pub(super) leaf: &'a SyntaxNode, pub(super) module: Option, pub(super) function: Option, - pub(super) function_syntax: Option>, - pub(super) use_item_syntax: Option>, + pub(super) function_syntax: Option<&'a ast::FnDef>, + pub(super) use_item_syntax: Option<&'a ast::UseItem>, pub(super) is_param: bool, /// A single-indent path, like `foo`. pub(super) is_trivial_path: bool, @@ -36,7 +32,7 @@ pub(super) struct CompletionContext<'a> { /// Something is typed at the "top" level, in module or impl/trait. pub(super) is_new_item: bool, /// The receiver if this is a field or method access, i.e. writing something.<|> - pub(super) dot_receiver: Option>, + pub(super) dot_receiver: Option<&'a ast::Expr>, /// If this is a method call in particular, i.e. the () are already there. pub(super) is_method_call: bool, } @@ -44,7 +40,7 @@ pub(super) struct CompletionContext<'a> { impl<'a> CompletionContext<'a> { pub(super) fn new( db: &'a db::RootDatabase, - original_file: &'a SourceFileNode, + original_file: &'a SourceFile, position: FilePosition, ) -> Cancelable>> { let module = source_binder::module_from_position(db, position)?; @@ -71,7 +67,7 @@ impl<'a> CompletionContext<'a> { Ok(Some(ctx)) } - fn fill(&mut self, original_file: &'a SourceFileNode, offset: TextUnit) { + fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { // Insert a fake ident to get a valid parse tree. We will use this file // to determine context, though the original_file will be used for // actual completion. @@ -100,7 +96,7 @@ impl<'a> CompletionContext<'a> { } } } - fn classify_name_ref(&mut self, original_file: &'a SourceFileNode, name_ref: ast::NameRef) { + fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) { let name_range = name_ref.syntax().range(); let top_node = name_ref .syntax() @@ -197,15 +193,12 @@ impl<'a> CompletionContext<'a> { } } -fn find_node_with_range<'a, N: AstNode<'a>>( - syntax: SyntaxNodeRef<'a>, - range: TextRange, -) -> Option { +fn find_node_with_range(syntax: &SyntaxNode, range: TextRange) -> Option<&N> { let node = find_covering_node(syntax, range); node.ancestors().find_map(N::cast) } -fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { +fn is_node(node: &SyntaxNode) -> bool { match node.ancestors().filter_map(N::cast).next() { None => false, Some(n) => n.syntax().range() == node.range(), -- cgit v1.2.3