mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Move original_file to Expander
This commit is contained in:
parent
8c8ef1432e
commit
e7e85c60d2
2 changed files with 11 additions and 9 deletions
|
@ -18,6 +18,7 @@ use crate::{
|
||||||
|
|
||||||
pub struct Expander {
|
pub struct Expander {
|
||||||
crate_def_map: Arc<CrateDefMap>,
|
crate_def_map: Arc<CrateDefMap>,
|
||||||
|
original_file_id: HirFileId,
|
||||||
current_file_id: HirFileId,
|
current_file_id: HirFileId,
|
||||||
module: ModuleId,
|
module: ModuleId,
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,12 @@ pub struct Expander {
|
||||||
impl Expander {
|
impl Expander {
|
||||||
pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander {
|
pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander {
|
||||||
let crate_def_map = db.crate_def_map(module.krate);
|
let crate_def_map = db.crate_def_map(module.krate);
|
||||||
Expander { crate_def_map, current_file_id, module }
|
Expander { crate_def_map, original_file_id: current_file_id, current_file_id, module }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: remove this.
|
||||||
|
fn is_in_expansion(&self) -> bool {
|
||||||
|
self.original_file_id != self.current_file_id
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use hir_expand::{
|
||||||
either::Either,
|
either::Either,
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
name::{self, AsName, Name},
|
name::{self, AsName, Name},
|
||||||
AstId, HirFileId, MacroCallLoc, MacroFileKind, Source,
|
AstId, MacroCallLoc, MacroFileKind, Source,
|
||||||
};
|
};
|
||||||
use ra_arena::Arena;
|
use ra_arena::Arena;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
|
@ -34,12 +34,9 @@ pub(super) fn lower(
|
||||||
params: Option<ast::ParamList>,
|
params: Option<ast::ParamList>,
|
||||||
body: Option<ast::Expr>,
|
body: Option<ast::Expr>,
|
||||||
) -> (Body, BodySourceMap) {
|
) -> (Body, BodySourceMap) {
|
||||||
let original_file_id = expander.current_file_id;
|
|
||||||
|
|
||||||
ExprCollector {
|
ExprCollector {
|
||||||
expander,
|
expander,
|
||||||
db,
|
db,
|
||||||
original_file_id,
|
|
||||||
source_map: BodySourceMap::default(),
|
source_map: BodySourceMap::default(),
|
||||||
body: Body {
|
body: Body {
|
||||||
exprs: Arena::default(),
|
exprs: Arena::default(),
|
||||||
|
@ -54,7 +51,6 @@ pub(super) fn lower(
|
||||||
struct ExprCollector<DB> {
|
struct ExprCollector<DB> {
|
||||||
db: DB,
|
db: DB,
|
||||||
expander: Expander,
|
expander: Expander,
|
||||||
original_file_id: HirFileId,
|
|
||||||
|
|
||||||
body: Body,
|
body: Body,
|
||||||
source_map: BodySourceMap,
|
source_map: BodySourceMap,
|
||||||
|
@ -100,7 +96,7 @@ where
|
||||||
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
||||||
let ptr = Either::A(ptr);
|
let ptr = Either::A(ptr);
|
||||||
let id = self.body.exprs.alloc(expr);
|
let id = self.body.exprs.alloc(expr);
|
||||||
if self.expander.current_file_id == self.original_file_id {
|
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
|
||||||
|
@ -116,7 +112,7 @@ where
|
||||||
fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
|
fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
|
||||||
let ptr = Either::B(ptr);
|
let ptr = Either::B(ptr);
|
||||||
let id = self.body.exprs.alloc(expr);
|
let id = self.body.exprs.alloc(expr);
|
||||||
if self.expander.current_file_id == self.original_file_id {
|
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
|
||||||
|
@ -126,7 +122,7 @@ where
|
||||||
}
|
}
|
||||||
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
|
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
|
||||||
let id = self.body.pats.alloc(pat);
|
let id = self.body.pats.alloc(pat);
|
||||||
if self.expander.current_file_id == self.original_file_id {
|
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
|
||||||
|
|
Loading…
Reference in a new issue