From 553254973e24a2c0bdf1475fccbbc4603e8421f0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 27 Feb 2020 00:12:26 +0800 Subject: Skip trival token in original_range --- crates/ra_hir/src/semantics.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 0b40bf9af..5b0b94e34 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -8,8 +8,9 @@ use hir_def::{ }; use ra_db::{FileId, FileRange}; use ra_syntax::{ - algo::find_covering_element, ast, match_ast, AstNode, NodeOrToken, SyntaxElement, SyntaxNode, - SyntaxToken, TextRange, TextUnit, + algo::{find_covering_element, skip_trivia_token}, + ast, match_ast, AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, + TextRange, TextUnit, }; use rustc_hash::{FxHashMap, FxHashSet}; @@ -384,11 +385,12 @@ fn original_range_and_origin( }; // the input node has only one token ? - let single = node.value.first_token()? == node.value.last_token()?; + let single = skip_trivia_token(node.value.first_token()?, Direction::Next)? + == skip_trivia_token(node.value.last_token()?, Direction::Prev)?; return Some(node.value.descendants().find_map(|it| { - let first = it.first_token()?; - let last = it.last_token()?; + let first = skip_trivia_token(it.first_token()?, Direction::Next)?; + let last = skip_trivia_token(it.last_token()?, Direction::Prev)?; if !single && first == last { return None; -- cgit v1.2.3