diff options
author | Edwin Cheng <[email protected]> | 2020-01-06 20:35:19 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-01-12 12:25:58 +0000 |
commit | 07f4171b1803f562118671255d73b97f20d24e07 (patch) | |
tree | 1aead3e38a7722019180b6bf5baa9bc317305507 /crates/ra_ide/src | |
parent | 4c4416543ab14c9a0a246907f41be0658f97c6fc (diff) |
Minor fix
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/extend_selection.rs | 9 |
1 files changed, 4 insertions, 5 deletions
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}; | |||
13 | use hir::{db::AstDatabase, InFile}; | 13 | use hir::{db::AstDatabase, InFile}; |
14 | use itertools::Itertools; | 14 | use itertools::Itertools; |
15 | 15 | ||
16 | // FIXME: restore macro support | ||
17 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { | 16 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { |
18 | let src = db.parse(frange.file_id).tree(); | 17 | let src = db.parse(frange.file_id).tree(); |
19 | let root = InFile::new(frange.file_id.into(), src.syntax()); | 18 | let root = InFile::new(frange.file_id.into(), src.syntax()); |
@@ -93,8 +92,7 @@ fn try_extend_selection( | |||
93 | return Some(node.text_range()); | 92 | return Some(node.text_range()); |
94 | } | 93 | } |
95 | 94 | ||
96 | // Using shallowest node with same range allows us to traverse siblings. | 95 | let node = shallowest_node(&node.into()).unwrap(); |
97 | let node = node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap(); | ||
98 | 96 | ||
99 | if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) { | 97 | if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) { |
100 | if let Some(range) = extend_list_item(&node) { | 98 | if let Some(range) = extend_list_item(&node) { |
@@ -129,7 +127,7 @@ fn extend_tokens_from_range( | |||
129 | .fold1(|x, y| union_range(x, y))?; | 127 | .fold1(|x, y| union_range(x, y))?; |
130 | 128 | ||
131 | let src = db.parse_or_expand(expansion.file_id())?; | 129 | 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()?; |
133 | 131 | ||
134 | // compute parent mapped token range | 132 | // compute parent mapped token range |
135 | let range = macro_call | 133 | let range = macro_call |
@@ -162,7 +160,8 @@ fn union_range(range: TextRange, r: TextRange) -> TextRange { | |||
162 | TextRange::from_to(start, end) | 160 | TextRange::from_to(start, end) |
163 | } | 161 | } |
164 | 162 | ||
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> { | ||
166 | node.ancestors().take_while(|n| n.text_range() == node.text_range()).last() | 165 | node.ancestors().take_while(|n| n.text_range() == node.text_range()).last() |
167 | } | 166 | } |
168 | 167 | ||