aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_expand/src/db.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index 3fd9a90a8..36d3307a1 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -138,16 +138,13 @@ pub fn expand_hypothetical(
138 Some((node.syntax_node(), token)) 138 Some((node.syntax_node(), token))
139} 139}
140 140
141pub(crate) fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> { 141fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
142 let map = 142 let map =
143 db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it)); 143 db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it));
144 Arc::new(map) 144 Arc::new(map)
145} 145}
146 146
147pub(crate) fn macro_def( 147fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
148 db: &dyn AstDatabase,
149 id: MacroDefId,
150) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
151 match id.kind { 148 match id.kind {
152 MacroDefKind::Declarative => { 149 MacroDefKind::Declarative => {
153 let macro_call = id.ast_id?.to_node(db); 150 let macro_call = id.ast_id?.to_node(db);
@@ -178,7 +175,7 @@ pub(crate) fn macro_def(
178 } 175 }
179} 176}
180 177
181pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> { 178fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
182 let id = match id { 179 let id = match id {
183 MacroCallId::LazyMacro(id) => id, 180 MacroCallId::LazyMacro(id) => id,
184 MacroCallId::EagerMacro(_id) => { 181 MacroCallId::EagerMacro(_id) => {
@@ -191,16 +188,13 @@ pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<Gr
191 Some(arg.green().clone()) 188 Some(arg.green().clone())
192} 189}
193 190
194pub(crate) fn macro_arg( 191fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
195 db: &dyn AstDatabase,
196 id: MacroCallId,
197) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
198 let arg = db.macro_arg_text(id)?; 192 let arg = db.macro_arg_text(id)?;
199 let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?; 193 let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?;
200 Some(Arc::new((tt, tmap))) 194 Some(Arc::new((tt, tmap)))
201} 195}
202 196
203pub(crate) fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> { 197fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> {
204 macro_expand_with_arg(db, id, None) 198 macro_expand_with_arg(db, id, None)
205} 199}
206 200
@@ -258,7 +252,7 @@ fn macro_expand_with_arg(
258 MacroResult { value: Some(Arc::new(tt)), error: err.map(|e| format!("{:?}", e)) } 252 MacroResult { value: Some(Arc::new(tt)), error: err.map(|e| format!("{:?}", e)) }
259} 253}
260 254
261pub(crate) fn expand_proc_macro( 255fn expand_proc_macro(
262 db: &dyn AstDatabase, 256 db: &dyn AstDatabase,
263 id: MacroCallId, 257 id: MacroCallId,
264) -> Result<tt::Subtree, mbe::ExpandError> { 258) -> Result<tt::Subtree, mbe::ExpandError> {
@@ -285,7 +279,7 @@ pub(crate) fn expand_proc_macro(
285 expander.expand(db, lazy_id, &macro_arg.0) 279 expander.expand(db, lazy_id, &macro_arg.0)
286} 280}
287 281
288pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> { 282fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
289 match file_id.0 { 283 match file_id.0 {
290 HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), 284 HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
291 HirFileIdRepr::MacroFile(macro_file) => { 285 HirFileIdRepr::MacroFile(macro_file) => {
@@ -294,14 +288,14 @@ pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Optio
294 } 288 }
295} 289}
296 290
297pub(crate) fn parse_macro( 291fn parse_macro(
298 db: &dyn AstDatabase, 292 db: &dyn AstDatabase,
299 macro_file: MacroFile, 293 macro_file: MacroFile,
300) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)> { 294) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)> {
301 parse_macro_with_arg(db, macro_file, None) 295 parse_macro_with_arg(db, macro_file, None)
302} 296}
303 297
304pub fn parse_macro_with_arg( 298fn parse_macro_with_arg(
305 db: &dyn AstDatabase, 299 db: &dyn AstDatabase,
306 macro_file: MacroFile, 300 macro_file: MacroFile,
307 arg: Option<Arc<(tt::Subtree, mbe::TokenMap)>>, 301 arg: Option<Arc<(tt::Subtree, mbe::TokenMap)>>,