aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/lib.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-11-03 14:46:12 +0000
committerEdwin Cheng <[email protected]>2019-11-04 17:38:20 +0000
commit159da285e9d8594a2cc4436b5cee7874b07806c9 (patch)
tree15630e1158cfb7d7305cedd93c1a644b28f9b776 /crates/ra_hir_expand/src/lib.rs
parent9fd546bec23ac817a45da28889e76118969db91e (diff)
Add macro_expansion_info in hir_expand
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r--crates/ra_hir_expand/src/lib.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index dd07a16b4..194020b45 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -16,7 +16,7 @@ use std::hash::{Hash, Hasher};
16use ra_db::{salsa, CrateId, FileId}; 16use ra_db::{salsa, CrateId, FileId};
17use ra_syntax::{ 17use ra_syntax::{
18 ast::{self, AstNode}, 18 ast::{self, AstNode},
19 SyntaxNode, 19 SyntaxNode, TextRange,
20}; 20};
21 21
22use crate::ast_id_map::FileAstId; 22use crate::ast_id_map::FileAstId;
@@ -112,6 +112,39 @@ impl MacroCallId {
112 } 112 }
113} 113}
114 114
115#[derive(Debug, Clone, PartialEq, Eq)]
116/// ExpansionInfo mainly describle how to map text range between src and expaned macro
117pub struct ExpansionInfo {
118 pub arg_map: Vec<(TextRange, TextRange)>,
119 pub def_map: Vec<(TextRange, TextRange)>,
120}
121
122impl ExpansionInfo {
123 pub fn find_range(
124 &self,
125 from: TextRange,
126 (arg_file_id, def_file_id): (HirFileId, HirFileId),
127 ) -> Option<(HirFileId, TextRange)> {
128 for (src, dest) in &self.arg_map {
129 dbg!((src, *dest, "arg_map"));
130 if src.is_subrange(&from) {
131 dbg!((arg_file_id, *dest));
132 return Some((arg_file_id, *dest));
133 }
134 }
135
136 for (src, dest) in &self.def_map {
137 dbg!((src, *dest, "def_map"));
138 if src.is_subrange(&from) {
139 dbg!((arg_file_id, *dest));
140 return Some((def_file_id, *dest));
141 }
142 }
143
144 None
145 }
146}
147
115/// `AstId` points to an AST node in any file. 148/// `AstId` points to an AST node in any file.
116/// 149///
117/// It is stable across reparses, and can be used as salsa key/value. 150/// It is stable across reparses, and can be used as salsa key/value.