Rename hygiene vars and fields to span_map

This commit is contained in:
Lukas Wirth 2023-11-25 15:37:40 +01:00
parent 6208960c48
commit ab8f12e169
13 changed files with 85 additions and 83 deletions

View file

@ -42,18 +42,18 @@ impl RawAttrs {
pub fn new(
db: &dyn ExpandDatabase,
owner: &dyn ast::HasAttrs,
hygiene: SpanMapRef<'_>,
span_map: SpanMapRef<'_>,
) -> Self {
let entries = collect_attrs(owner)
.filter_map(|(id, attr)| match attr {
Either::Left(attr) => {
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
attr.meta().and_then(|meta| Attr::from_src(db, meta, span_map, id))
}
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
id,
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
path: Interned::new(ModPath::from(crate::name!(doc))),
ctxt: hygiene.span_for_range(comment.syntax().text_range()).ctx,
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
}),
})
.collect::<Vec<_>>();
@ -66,9 +66,9 @@ impl RawAttrs {
pub fn from_attrs_owner(
db: &dyn ExpandDatabase,
owner: InFile<&dyn ast::HasAttrs>,
hygiene: SpanMapRef<'_>,
span_map: SpanMapRef<'_>,
) -> Self {
Self::new(db, owner.value, hygiene)
Self::new(db, owner.value, span_map)
}
pub fn merge(&self, other: Self) -> Self {
@ -216,10 +216,10 @@ impl Attr {
fn from_src(
db: &dyn ExpandDatabase,
ast: ast::Meta,
hygiene: SpanMapRef<'_>,
span_map: SpanMapRef<'_>,
id: AttrId,
) -> Option<Attr> {
let path = Interned::new(ModPath::from_src(db, ast.path()?, hygiene)?);
let path = Interned::new(ModPath::from_src(db, ast.path()?, span_map)?);
let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
let value = match lit.kind() {
ast::LiteralKind::String(string) => string.value()?.into(),
@ -227,12 +227,12 @@ impl Attr {
};
Some(Interned::new(AttrInput::Literal(value)))
} else if let Some(tt) = ast.token_tree() {
let tree = syntax_node_to_token_tree(tt.syntax(), hygiene);
let tree = syntax_node_to_token_tree(tt.syntax(), span_map);
Some(Interned::new(AttrInput::TokenTree(Box::new(tree))))
} else {
None
};
Some(Attr { id, path, input, ctxt: hygiene.span_for_range(ast.syntax().text_range()).ctx })
Some(Attr { id, path, input, ctxt: span_map.span_for_range(ast.syntax().text_range()).ctx })
}
fn from_tt(db: &dyn ExpandDatabase, tt: &tt::Subtree, id: AttrId) -> Option<Attr> {

View file

@ -127,7 +127,7 @@ fn lazy_expand(
fn eager_macro_recur(
db: &dyn ExpandDatabase,
hygiene: &ExpansionSpanMap,
span_map: &ExpansionSpanMap,
curr: InFile<SyntaxNode>,
krate: CrateId,
call_site: SyntaxContextId,
@ -170,7 +170,7 @@ fn eager_macro_recur(
};
let def = match call
.path()
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(hygiene)))
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(span_map)))
{
Some(path) => match macro_resolver(path.clone()) {
Some(def) => def,

View file

@ -47,9 +47,9 @@ impl ModPath {
pub fn from_src(
db: &dyn ExpandDatabase,
path: ast::Path,
hygiene: SpanMapRef<'_>,
span_map: SpanMapRef<'_>,
) -> Option<ModPath> {
convert_path(db, None, path, hygiene)
convert_path(db, None, path, span_map)
}
pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
@ -194,10 +194,10 @@ fn convert_path(
db: &dyn ExpandDatabase,
prefix: Option<ModPath>,
path: ast::Path,
hygiene: SpanMapRef<'_>,
span_map: SpanMapRef<'_>,
) -> Option<ModPath> {
let prefix = match path.qualifier() {
Some(qual) => Some(convert_path(db, prefix, qual, hygiene)?),
Some(qual) => Some(convert_path(db, prefix, qual, span_map)?),
None => prefix,
};
@ -211,7 +211,7 @@ fn convert_path(
ModPath::from_kind(
resolve_crate_root(
db,
hygiene.span_for_range(name_ref.syntax().text_range()).ctx,
span_map.span_for_range(name_ref.syntax().text_range()).ctx,
)
.map(PathKind::DollarCrate)
.unwrap_or(PathKind::Crate),
@ -265,7 +265,7 @@ fn convert_path(
// We follow what it did anyway :)
if mod_path.segments.len() == 1 && mod_path.kind == PathKind::Plain {
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
let syn_ctx = hygiene.span_for_range(segment.syntax().text_range()).ctx;
let syn_ctx = span_map.span_for_range(segment.syntax().text_range()).ctx;
if let Some(macro_call_id) = db.lookup_intern_syntax_context(syn_ctx).outer_expn {
if db.lookup_intern_macro_call(macro_call_id).def.local_inner {
mod_path.kind = match resolve_crate_root(db, syn_ctx) {