aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/expand.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/expand.rs')
-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(