Some final touches

This commit is contained in:
Lukas Wirth 2023-12-03 18:50:29 +01:00
parent 81410ab500
commit 18f1a3c3c6
10 changed files with 86 additions and 67 deletions

View file

@ -663,7 +663,7 @@ impl ExpansionInfo {
range: TextRange,
) -> Option<(FileRange, SyntaxContextId)> {
debug_assert!(self.expanded.value.text_range().contains_range(range));
let mut spans = self.exp_map.spans_for_node_range(range);
let mut spans = self.exp_map.spans_for_range(range);
let SpanData { range, anchor, ctx } = spans.next()?;
let mut start = range.start();
let mut end = range.end();

View file

@ -215,10 +215,18 @@ impl_to_to_tokentrees! {
#[cfg(test)]
mod tests {
use crate::tt;
use ::tt::Span;
use base_db::{
span::{SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID},
FileId,
};
use expect_test::expect;
use syntax::{TextRange, TextSize};
const DUMMY: tt::SpanData = tt::SpanData::DUMMY;
const DUMMY: tt::SpanData = tt::SpanData {
range: TextRange::empty(TextSize::new(0)),
anchor: SpanAnchor { file_id: FileId::BOGUS, ast_id: ROOT_ERASED_FILE_AST_ID },
ctx: SyntaxContextId::ROOT,
};
#[test]
fn test_quote_delimiters() {
@ -242,10 +250,7 @@ mod tests {
}
fn mk_ident(name: &str) -> crate::tt::Ident {
crate::tt::Ident {
text: name.into(),
span: <crate::tt::SpanData as crate::tt::Span>::DUMMY,
}
crate::tt::Ident { text: name.into(), span: DUMMY }
}
#[test]
@ -256,8 +261,8 @@ mod tests {
assert_eq!(quoted.to_string(), "hello");
let t = format!("{quoted:?}");
expect![[r#"
SUBTREE $$ SpanData { range: 0..0, anchor: SpanAnchor(FileId(0), 0), ctx: SyntaxContextId(0) } SpanData { range: 0..0, anchor: SpanAnchor(FileId(0), 0), ctx: SyntaxContextId(0) }
IDENT hello SpanData { range: 0..0, anchor: SpanAnchor(FileId(0), 0), ctx: SyntaxContextId(0) }"#]].assert_eq(&t);
SUBTREE $$ SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) } SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) }
IDENT hello SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) }"#]].assert_eq(&t);
}
#[test]
@ -290,8 +295,8 @@ mod tests {
let list = crate::tt::Subtree {
delimiter: crate::tt::Delimiter {
kind: crate::tt::DelimiterKind::Brace,
open: <crate::tt::SpanData as crate::tt::Span>::DUMMY,
close: <crate::tt::SpanData as crate::tt::Span>::DUMMY,
open: DUMMY,
close: DUMMY,
},
token_trees: fields.collect(),
};

View file

@ -4,13 +4,12 @@ use base_db::{
span::{ErasedFileAstId, SpanAnchor, SpanData, SyntaxContextId, ROOT_ERASED_FILE_AST_ID},
FileId,
};
use mbe::TokenMap;
use syntax::{ast::HasModuleItem, AstNode, TextRange, TextSize};
use triomphe::Arc;
use crate::db::ExpandDatabase;
pub type ExpansionSpanMap = TokenMap<SpanData>;
pub type ExpansionSpanMap = mbe::SpanMap<SpanData>;
/// Spanmap for a macro file or a real file
#[derive(Clone, Debug, PartialEq, Eq)]