Skip to content

Commit 07f4171

Browse files
committed
Minor fix
1 parent 4c44165 commit 07f4171

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

crates/ra_ide/src/extend_selection.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{db::RootDatabase, FileRange};
1313
use hir::{db::AstDatabase, InFile};
1414
use itertools::Itertools;
1515

16-
// FIXME: restore macro support
1716
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
1817
let src = db.parse(frange.file_id).tree();
1918
let root = InFile::new(frange.file_id.into(), src.syntax());
@@ -93,8 +92,7 @@ fn try_extend_selection(
9392
return Some(node.text_range());
9493
}
9594

96-
// Using shallowest node with same range allows us to traverse siblings.
97-
let node = node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap();
95+
let node = shallowest_node(&node.into()).unwrap();
9896

9997
if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
10098
if let Some(range) = extend_list_item(&node) {
@@ -129,7 +127,7 @@ fn extend_tokens_from_range(
129127
.fold1(|x, y| union_range(x, y))?;
130128

131129
let src = db.parse_or_expand(expansion.file_id())?;
132-
let parent = shallow_node(&find_covering_element(&src, range))?.parent()?;
130+
let parent = shallowest_node(&find_covering_element(&src, range))?.parent()?;
133131

134132
// compute parent mapped token range
135133
let range = macro_call
@@ -162,7 +160,8 @@ fn union_range(range: TextRange, r: TextRange) -> TextRange {
162160
TextRange::from_to(start, end)
163161
}
164162

165-
fn shallow_node(node: &SyntaxElement) -> Option<SyntaxNode> {
163+
/// Find the shallowest node with same range, which allows us to traverse siblings.
164+
fn shallowest_node(node: &SyntaxElement) -> Option<SyntaxNode> {
166165
node.ancestors().take_while(|n| n.text_range() == node.text_range()).last()
167166
}
168167

0 commit comments

Comments
 (0)