diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/extend_selection.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/extend_selection.rs b/crates/ra_analysis/src/extend_selection.rs index cde6ee101..805e9059e 100644 --- a/crates/ra_analysis/src/extend_selection.rs +++ b/crates/ra_analysis/src/extend_selection.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use ra_db::SyntaxDatabase; | 1 | use ra_db::SyntaxDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | SyntaxNodeRef, AstNode, | 3 | SyntaxNodeRef, AstNode, SourceFileNode, |
4 | ast, algo::find_covering_node, | 4 | ast, algo::find_covering_node, |
5 | }; | 5 | }; |
6 | 6 | ||
@@ -11,18 +11,23 @@ use crate::{ | |||
11 | 11 | ||
12 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { | 12 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { |
13 | let source_file = db.source_file(frange.file_id); | 13 | let source_file = db.source_file(frange.file_id); |
14 | if let Some(macro_call) = find_macro_call(source_file.syntax(), frange.range) { | 14 | if let Some(range) = extend_selection_in_macro(db, &source_file, frange) { |
15 | if let Some(exp) = crate::macros::expand(db, frange.file_id, macro_call) { | 15 | return range; |
16 | if let Some(dst_range) = exp.map_range_forward(frange.range) { | ||
17 | if let Some(dst_range) = ra_editor::extend_selection(exp.source_file(), dst_range) { | ||
18 | if let Some(src_range) = exp.map_range_back(dst_range) { | ||
19 | return src_range; | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | } | 16 | } |
25 | ra_editor::extend_selection(&source_file, frange.range).unwrap_or(frange.range) | 17 | ra_editor::extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range) |
18 | } | ||
19 | |||
20 | fn extend_selection_in_macro( | ||
21 | db: &RootDatabase, | ||
22 | source_file: &SourceFileNode, | ||
23 | frange: FileRange, | ||
24 | ) -> Option<TextRange> { | ||
25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; | ||
26 | let exp = crate::macros::expand(db, frange.file_id, macro_call)?; | ||
27 | let dst_range = exp.map_range_forward(frange.range)?; | ||
28 | let dst_range = ra_editor::extend_selection(exp.source_file().syntax(), dst_range)?; | ||
29 | let src_range = exp.map_range_back(dst_range)?; | ||
30 | Some(src_range) | ||
26 | } | 31 | } |
27 | 32 | ||
28 | fn find_macro_call(node: SyntaxNodeRef, range: TextRange) -> Option<ast::MacroCall> { | 33 | fn find_macro_call(node: SyntaxNodeRef, range: TextRange) -> Option<ast::MacroCall> { |