diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-31 16:06:27 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-31 16:06:27 +0000 |
commit | 6044ec50572747a1a096133d7f71c2d3d689bbf3 (patch) | |
tree | 221c39c9ce30900c8d0c1ede30258343523d1942 /crates/ra_analysis/src | |
parent | 2a65020442142b68b32c0a97672faeeba5ff399e (diff) | |
parent | 862c99d0d5ef7c791a9319fa76c436762d88460c (diff) |
Merge #395
395: generalize r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/extend_selection.rs | 29 | ||||
-rw-r--r-- | crates/ra_analysis/src/syntax_highlighting.rs | 4 |
2 files changed, 19 insertions, 14 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> { |
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 38219da71..7e9139a74 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs | |||
@@ -9,14 +9,14 @@ use crate::{ | |||
9 | 9 | ||
10 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 10 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
11 | let source_file = db.source_file(file_id); | 11 | let source_file = db.source_file(file_id); |
12 | let mut res = ra_editor::highlight(&source_file); | 12 | let mut res = ra_editor::highlight(source_file.syntax()); |
13 | for macro_call in source_file | 13 | for macro_call in source_file |
14 | .syntax() | 14 | .syntax() |
15 | .descendants() | 15 | .descendants() |
16 | .filter_map(ast::MacroCall::cast) | 16 | .filter_map(ast::MacroCall::cast) |
17 | { | 17 | { |
18 | if let Some(exp) = crate::macros::expand(db, file_id, macro_call) { | 18 | if let Some(exp) = crate::macros::expand(db, file_id, macro_call) { |
19 | let mapped_ranges = ra_editor::highlight(exp.source_file()) | 19 | let mapped_ranges = ra_editor::highlight(exp.source_file().syntax()) |
20 | .into_iter() | 20 | .into_iter() |
21 | .filter_map(|r| { | 21 | .filter_map(|r| { |
22 | let mapped_range = exp.map_range_back(r.range)?; | 22 | let mapped_range = exp.map_range_back(r.range)?; |