mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 03:27:44 +00:00
Record macro def site spans
This commit is contained in:
parent
51a9e7831a
commit
7d762d18ed
@ -326,7 +326,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
|||||||
|
|
||||||
match id {
|
match id {
|
||||||
MacroId::Macro2Id(it) => {
|
MacroId::Macro2Id(it) => {
|
||||||
let loc = it.lookup(db);
|
let loc: Macro2Loc = it.lookup(db);
|
||||||
|
|
||||||
let item_tree = loc.id.item_tree(db);
|
let item_tree = loc.id.item_tree(db);
|
||||||
let makro = &item_tree[loc.id.value];
|
let makro = &item_tree[loc.id.value];
|
||||||
@ -335,10 +335,13 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
|||||||
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
||||||
local_inner: false,
|
local_inner: false,
|
||||||
allow_internal_unsafe: loc.allow_internal_unsafe,
|
allow_internal_unsafe: loc.allow_internal_unsafe,
|
||||||
|
def_site: db
|
||||||
|
.span_map(loc.id.file_id())
|
||||||
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MacroId::MacroRulesId(it) => {
|
MacroId::MacroRulesId(it) => {
|
||||||
let loc = it.lookup(db);
|
let loc: MacroRulesLoc = it.lookup(db);
|
||||||
|
|
||||||
let item_tree = loc.id.item_tree(db);
|
let item_tree = loc.id.item_tree(db);
|
||||||
let makro = &item_tree[loc.id.value];
|
let makro = &item_tree[loc.id.value];
|
||||||
@ -347,6 +350,9 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
|||||||
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
|
||||||
local_inner: loc.local_inner,
|
local_inner: loc.local_inner,
|
||||||
allow_internal_unsafe: loc.allow_internal_unsafe,
|
allow_internal_unsafe: loc.allow_internal_unsafe,
|
||||||
|
def_site: db
|
||||||
|
.span_map(loc.id.file_id())
|
||||||
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MacroId::ProcMacroId(it) => {
|
MacroId::ProcMacroId(it) => {
|
||||||
@ -363,6 +369,9 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
|
|||||||
),
|
),
|
||||||
local_inner: false,
|
local_inner: false,
|
||||||
allow_internal_unsafe: false,
|
allow_internal_unsafe: false,
|
||||||
|
def_site: db
|
||||||
|
.span_map(loc.id.file_id())
|
||||||
|
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ pub struct MacroDefId {
|
|||||||
pub kind: MacroDefKind,
|
pub kind: MacroDefKind,
|
||||||
pub local_inner: bool,
|
pub local_inner: bool,
|
||||||
pub allow_internal_unsafe: bool,
|
pub allow_internal_unsafe: bool,
|
||||||
// pub def_site: Span,
|
pub def_site: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
@ -38,6 +38,10 @@ impl mbe::SpanMapper<Span> for SpanMapRef<'_> {
|
|||||||
impl SpanMap {
|
impl SpanMap {
|
||||||
pub fn span_for_range(&self, range: TextRange) -> Span {
|
pub fn span_for_range(&self, range: TextRange) -> Span {
|
||||||
match self {
|
match self {
|
||||||
|
// FIXME: Is it correct for us to only take the span at the start? This feels somewhat
|
||||||
|
// wrong. The context will be right, but the range could be considered wrong. See
|
||||||
|
// https://github.com/rust-lang/rust/issues/23480, we probably want to fetch the span at
|
||||||
|
// the start and end, then merge them like rustc does in `Span::to
|
||||||
Self::ExpansionSpanMap(span_map) => span_map.span_at(range.start()),
|
Self::ExpansionSpanMap(span_map) => span_map.span_at(range.start()),
|
||||||
Self::RealSpanMap(span_map) => span_map.span_for_range(range),
|
Self::RealSpanMap(span_map) => span_map.span_for_range(range),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user