aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-18 12:09:24 +0000
committerGitHub <[email protected]>2019-11-18 12:09:24 +0000
commit157beb8b3fd162b2be735274d5da42870e90cb01 (patch)
tree3985535b59ac5061f3c6fb7ce9c109b454dc2c1e /crates/ra_ide_api
parent32e72ecd66fede0b39e8f34ca3e1b92128e1d91a (diff)
parentb79d6789236bb53c5818949cc2960b5c4991cbeb (diff)
Merge #2300
2300: Token-based reverse-mapping r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/expand.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/crates/ra_ide_api/src/expand.rs b/crates/ra_ide_api/src/expand.rs
index 5f1fb9a12..7f59e46d2 100644
--- a/crates/ra_ide_api/src/expand.rs
+++ b/crates/ra_ide_api/src/expand.rs
@@ -8,15 +8,32 @@ use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken};
8use crate::{db::RootDatabase, FileRange}; 8use crate::{db::RootDatabase, FileRange};
9 9
10pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> FileRange { 10pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> FileRange {
11 let text_range = node.ast.text_range(); 11 let expansion = match node.file_id.expansion_info(db) {
12 let (file_id, range) = node 12 None => {
13 .file_id 13 return FileRange {
14 .expansion_info(db) 14 file_id: node.file_id.original_file(db),
15 .and_then(|expansion_info| expansion_info.find_range(text_range)) 15 range: node.ast.text_range(),
16 .unwrap_or((node.file_id, text_range)); 16 }
17 }
18 Some(it) => it,
19 };
20 // FIXME: the following completely wrong.
21 //
22 // *First*, we should try to map first and last tokens of node, and, if that
23 // fails, return the range of the overall macro expansions.
24 //
25 // *Second*, we should handle recurside macro expansions
26
27 let token = node
28 .ast
29 .descendants_with_tokens()
30 .filter_map(|it| it.into_token())
31 .find_map(|it| expansion.map_token_up(node.with_ast(&it)));
17 32
18 // FIXME: handle recursive macro generated macro 33 match token {
19 FileRange { file_id: file_id.original_file(db), range } 34 Some(it) => FileRange { file_id: it.file_id.original_file(db), range: it.ast.text_range() },
35 None => FileRange { file_id: node.file_id.original_file(db), range: node.ast.text_range() },
36 }
20} 37}
21 38
22pub(crate) fn descend_into_macros( 39pub(crate) fn descend_into_macros(