diff options
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 35 |
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}; | |||
16 | use ra_db::{salsa, CrateId, FileId}; | 16 | use ra_db::{salsa, CrateId, FileId}; |
17 | use ra_syntax::{ | 17 | use ra_syntax::{ |
18 | ast::{self, AstNode}, | 18 | ast::{self, AstNode}, |
19 | SyntaxNode, | 19 | SyntaxNode, TextRange, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | use crate::ast_id_map::FileAstId; | 22 | use 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 | ||
117 | pub struct ExpansionInfo { | ||
118 | pub arg_map: Vec<(TextRange, TextRange)>, | ||
119 | pub def_map: Vec<(TextRange, TextRange)>, | ||
120 | } | ||
121 | |||
122 | impl 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. |