From 07f4171b1803f562118671255d73b97f20d24e07 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 7 Jan 2020 04:35:19 +0800 Subject: Minor fix --- crates/ra_ide/src/extend_selection.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index e48ef8649..9b6cc15e8 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -13,7 +13,6 @@ use crate::{db::RootDatabase, FileRange}; use hir::{db::AstDatabase, InFile}; use itertools::Itertools; -// FIXME: restore macro support pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { let src = db.parse(frange.file_id).tree(); let root = InFile::new(frange.file_id.into(), src.syntax()); @@ -93,8 +92,7 @@ fn try_extend_selection( return Some(node.text_range()); } - // Using shallowest node with same range allows us to traverse siblings. - let node = node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap(); + let node = shallowest_node(&node.into()).unwrap(); if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) { if let Some(range) = extend_list_item(&node) { @@ -129,7 +127,7 @@ fn extend_tokens_from_range( .fold1(|x, y| union_range(x, y))?; let src = db.parse_or_expand(expansion.file_id())?; - let parent = shallow_node(&find_covering_element(&src, range))?.parent()?; + let parent = shallowest_node(&find_covering_element(&src, range))?.parent()?; // compute parent mapped token range let range = macro_call @@ -162,7 +160,8 @@ fn union_range(range: TextRange, r: TextRange) -> TextRange { TextRange::from_to(start, end) } -fn shallow_node(node: &SyntaxElement) -> Option { +/// Find the shallowest node with same range, which allows us to traverse siblings. +fn shallowest_node(node: &SyntaxElement) -> Option { node.ancestors().take_while(|n| n.text_range() == node.text_range()).last() } -- cgit v1.2.3