From 9e213385c9d06db3c8ca20812779e2b8f8ad2c71 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 30 Mar 2019 13:25:53 +0300 Subject: switch to new rowan --- .../ra_ide_api/src/completion/complete_fn_param.rs | 2 +- .../ra_ide_api/src/completion/complete_keyword.rs | 8 ++++---- .../src/completion/completion_context.rs | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide_api/src/completion') diff --git a/crates/ra_ide_api/src/completion/complete_fn_param.rs b/crates/ra_ide_api/src/completion/complete_fn_param.rs index ffdc744b2..f87ccdeb9 100644 --- a/crates/ra_ide_api/src/completion/complete_fn_param.rs +++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs @@ -17,7 +17,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } let mut params = FxHashMap::default(); - for node in ctx.leaf.ancestors() { + for node in ctx.token.parent().ancestors() { let _ = visitor_ctx(&mut params) .visit::(process) .visit::(process) diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs index 841c0c554..718b83418 100644 --- a/crates/ra_ide_api/src/completion/complete_keyword.rs +++ b/crates/ra_ide_api/src/completion/complete_keyword.rs @@ -2,7 +2,7 @@ use ra_syntax::{ algo::visit::{visitor, Visitor}, AstNode, ast::{self, LoopBodyOwner}, - SyntaxKind::*, SyntaxNode, + SyntaxKind::*, SyntaxToken, }; use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; @@ -62,7 +62,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte acc.add(keyword(ctx, "else", "else {$0}")); acc.add(keyword(ctx, "else if", "else if $0 {}")); } - if is_in_loop_body(ctx.leaf) { + if is_in_loop_body(ctx.token) { if ctx.can_be_stmt { acc.add(keyword(ctx, "continue", "continue;")); acc.add(keyword(ctx, "break", "break;")); @@ -74,8 +74,8 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte acc.add_all(complete_return(ctx, fn_def, ctx.can_be_stmt)); } -fn is_in_loop_body(leaf: &SyntaxNode) -> bool { - for node in leaf.ancestors() { +fn is_in_loop_body(leaf: SyntaxToken) -> bool { + for node in leaf.parent().ancestors() { if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { break; } diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 724d0dfbf..65dffa470 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -1,8 +1,8 @@ use ra_text_edit::AtomTextEdit; use ra_syntax::{ - AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, + AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, ast, - algo::{find_leaf_at_offset, find_covering_node, find_node_at_offset}, + algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, SyntaxKind::*, }; use hir::{source_binder, Resolver}; @@ -15,7 +15,7 @@ use crate::{db, FilePosition}; pub(crate) struct CompletionContext<'a> { pub(super) db: &'a db::RootDatabase, pub(super) offset: TextUnit, - pub(super) leaf: &'a SyntaxNode, + pub(super) token: SyntaxToken<'a>, pub(super) resolver: Resolver, pub(super) module: Option, pub(super) function: Option, @@ -49,10 +49,10 @@ impl<'a> CompletionContext<'a> { ) -> Option> { let resolver = source_binder::resolver_for_position(db, position); let module = source_binder::module_from_position(db, position); - let leaf = find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()?; + let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; let mut ctx = CompletionContext { db, - leaf, + token, offset: position.offset, resolver, module, @@ -76,9 +76,9 @@ impl<'a> CompletionContext<'a> { // The range of the identifier that is being completed. pub(crate) fn source_range(&self) -> TextRange { - match self.leaf.kind() { + match self.token.kind() { // workaroud when completion is triggered by trigger characters. - IDENT => self.leaf.range(), + IDENT => self.token.range(), _ => TextRange::offset_len(self.offset, 0.into()), } } @@ -139,10 +139,11 @@ impl<'a> CompletionContext<'a> { _ => (), } - self.use_item_syntax = self.leaf.ancestors().find_map(ast::UseItem::cast); + self.use_item_syntax = self.token.parent().ancestors().find_map(ast::UseItem::cast); self.function_syntax = self - .leaf + .token + .parent() .ancestors() .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) .find_map(ast::FnDef::cast); @@ -224,8 +225,7 @@ impl<'a> CompletionContext<'a> { } fn find_node_with_range(syntax: &SyntaxNode, range: TextRange) -> Option<&N> { - let node = find_covering_node(syntax, range); - node.ancestors().find_map(N::cast) + find_covering_element(syntax, range).ancestors().find_map(N::cast) } fn is_node(node: &SyntaxNode) -> bool { -- cgit v1.2.3