Add Expader::to_source

This commit is contained in:
Aleksey Kladov 2019-11-14 09:43:59 +03:00
parent e7e85c60d2
commit c89010df2d
2 changed files with 8 additions and 10 deletions

View file

@ -34,6 +34,10 @@ impl Expander {
self.original_file_id != self.current_file_id self.original_file_id != self.current_file_id
} }
fn to_source<T>(&self, ast: T) -> Source<T> {
Source { file_id: self.current_file_id, ast }
}
fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> { fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros()
} }

View file

@ -4,7 +4,7 @@ use hir_expand::{
either::Either, either::Either,
hygiene::Hygiene, hygiene::Hygiene,
name::{self, AsName, Name}, name::{self, AsName, Name},
AstId, MacroCallLoc, MacroFileKind, Source, AstId, MacroCallLoc, MacroFileKind,
}; };
use ra_arena::Arena; use ra_arena::Arena;
use ra_syntax::{ use ra_syntax::{
@ -99,9 +99,7 @@ where
if !self.expander.is_in_expansion() { if !self.expander.is_in_expansion() {
self.source_map.expr_map.insert(ptr, id); self.source_map.expr_map.insert(ptr, id);
} }
self.source_map self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr));
.expr_map_back
.insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
id id
} }
// desugared exprs don't have ptr, that's wrong and should be fixed // desugared exprs don't have ptr, that's wrong and should be fixed
@ -115,9 +113,7 @@ where
if !self.expander.is_in_expansion() { if !self.expander.is_in_expansion() {
self.source_map.expr_map.insert(ptr, id); self.source_map.expr_map.insert(ptr, id);
} }
self.source_map self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr));
.expr_map_back
.insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
id id
} }
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
@ -125,9 +121,7 @@ where
if !self.expander.is_in_expansion() { if !self.expander.is_in_expansion() {
self.source_map.pat_map.insert(ptr, id); self.source_map.pat_map.insert(ptr, id);
} }
self.source_map self.source_map.pat_map_back.insert(id, self.expander.to_source(ptr));
.pat_map_back
.insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
id id
} }