mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
internal: port rust-analyzer to new Salsa
This commit is contained in:
parent
394374e769
commit
74620e64ec
161 changed files with 3075 additions and 2331 deletions
|
|
@ -1931,11 +1931,11 @@ impl ExprCollector<'_> {
|
|||
None => (HygieneId::ROOT, None),
|
||||
Some(span_map) => {
|
||||
let span = span_map.span_at(lifetime.syntax().text_range().start());
|
||||
let ctx = self.db.lookup_intern_syntax_context(span.ctx);
|
||||
let hygiene_id = HygieneId::new(ctx.opaque_and_semitransparent);
|
||||
let hygiene_info = ctx.outer_expn.map(|expansion| {
|
||||
let ctx = span.ctx;
|
||||
let hygiene_id = HygieneId::new(ctx.opaque_and_semitransparent(self.db));
|
||||
let hygiene_info = ctx.outer_expn(self.db).map(|expansion| {
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion);
|
||||
(ctx.parent, expansion.def)
|
||||
(ctx.parent(self.db), expansion.def)
|
||||
});
|
||||
(hygiene_id, hygiene_info)
|
||||
}
|
||||
|
|
@ -1962,11 +1962,12 @@ impl ExprCollector<'_> {
|
|||
// A macro is allowed to refer to labels from before its declaration.
|
||||
// Therefore, if we got to the rib of its declaration, give up its hygiene
|
||||
// and use its parent expansion.
|
||||
let parent_ctx = self.db.lookup_intern_syntax_context(parent_ctx);
|
||||
hygiene_id = HygieneId::new(parent_ctx.opaque_and_semitransparent);
|
||||
hygiene_info = parent_ctx.outer_expn.map(|expansion| {
|
||||
|
||||
hygiene_id =
|
||||
HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
|
||||
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion);
|
||||
(parent_ctx.parent, expansion.def)
|
||||
(parent_ctx.parent(self.db), expansion.def)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2593,7 +2594,7 @@ impl ExprCollector<'_> {
|
|||
None => HygieneId::ROOT,
|
||||
Some(span_map) => {
|
||||
let ctx = span_map.span_at(span_start).ctx;
|
||||
HygieneId::new(self.db.lookup_intern_syntax_context(ctx).opaque_and_semitransparent)
|
||||
HygieneId::new(ctx.opaque_and_semitransparent(self.db))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,8 +324,9 @@ fn compute_expr_scopes(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use base_db::SourceDatabase;
|
||||
use base_db::RootQueryDb;
|
||||
use hir_expand::{name::AsName, InFile};
|
||||
use salsa::AsDynDatabase;
|
||||
use span::FileId;
|
||||
use syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
use test_fixture::WithFixture;
|
||||
|
|
@ -357,18 +358,22 @@ mod tests {
|
|||
};
|
||||
|
||||
let (db, position) = TestDB::with_position(&code);
|
||||
let file_id = position.file_id;
|
||||
let editioned_file_id = position.file_id;
|
||||
let offset = position.offset;
|
||||
|
||||
let file_syntax = db.parse(file_id).syntax_node();
|
||||
let (file_id, _) = editioned_file_id.unpack();
|
||||
let editioned_file_id_wrapper =
|
||||
base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
|
||||
|
||||
let file_syntax = db.parse(editioned_file_id_wrapper).syntax_node();
|
||||
let marker: ast::PathExpr = find_node_at_offset(&file_syntax, offset).unwrap();
|
||||
let function = find_function(&db, file_id.file_id());
|
||||
let function = find_function(&db, file_id);
|
||||
|
||||
let scopes = db.expr_scopes(function.into());
|
||||
let (_body, source_map) = db.body_with_source_map(function.into());
|
||||
|
||||
let expr_id = source_map
|
||||
.node_expr(InFile { file_id: file_id.into(), value: &marker.into() })
|
||||
.node_expr(InFile { file_id: editioned_file_id.into(), value: &marker.into() })
|
||||
.unwrap()
|
||||
.as_expr()
|
||||
.unwrap();
|
||||
|
|
@ -511,15 +516,19 @@ fn foo() {
|
|||
|
||||
fn do_check_local_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_offset: u32) {
|
||||
let (db, position) = TestDB::with_position(ra_fixture);
|
||||
let file_id = position.file_id;
|
||||
let editioned_file_id = position.file_id;
|
||||
let offset = position.offset;
|
||||
|
||||
let file = db.parse(file_id).ok().unwrap();
|
||||
let (file_id, _) = editioned_file_id.unpack();
|
||||
let file_id_wrapper =
|
||||
base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
|
||||
|
||||
let file = db.parse(file_id_wrapper).ok().unwrap();
|
||||
let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
|
||||
.expect("failed to find a name at the target offset");
|
||||
let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset).unwrap();
|
||||
|
||||
let function = find_function(&db, file_id.file_id());
|
||||
let function = find_function(&db, file_id);
|
||||
|
||||
let scopes = db.expr_scopes(function.into());
|
||||
let (_, source_map) = db.body_with_source_map(function.into());
|
||||
|
|
@ -527,7 +536,7 @@ fn foo() {
|
|||
let expr_scope = {
|
||||
let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap();
|
||||
let expr_id = source_map
|
||||
.node_expr(InFile { file_id: file_id.into(), value: &expr_ast })
|
||||
.node_expr(InFile { file_id: editioned_file_id.into(), value: &expr_ast })
|
||||
.unwrap()
|
||||
.as_expr()
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -189,8 +189,8 @@ fn f() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
BlockId(1) in BlockRelativeModuleId { block: Some(BlockId(0)), local_id: Idx::<ModuleData>(1) }
|
||||
BlockId(0) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
||||
BlockId(4c01) in BlockRelativeModuleId { block: Some(BlockId(4c00)), local_id: Idx::<ModuleData>(1) }
|
||||
BlockId(4c00) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
||||
crate scope
|
||||
"#]],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue