Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/test_db.rs')
| -rw-r--r-- | crates/hir-def/src/test_db.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs index 1e2f354f97..3bb9c361b3 100644 --- a/crates/hir-def/src/test_db.rs +++ b/crates/hir-def/src/test_db.rs @@ -7,7 +7,7 @@ use base_db::{ SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, }; use hir_expand::{InFile, files::FilePosition}; -use salsa::{AsDynDatabase, Durability}; +use salsa::Durability; use span::FileId; use syntax::{AstNode, algo, ast}; use triomphe::Arc; @@ -190,7 +190,15 @@ impl TestDB { let mut res = DefMap::ROOT; for (module, data) in def_map.modules() { let src = data.definition_source(self); - if src.file_id != position.file_id { + // We're not comparing the `base_db::EditionedFileId`, but rather the VFS `FileId`, because + // `position.file_id` is created before the def map, causing it to have to wrong crate + // attached often, which means it won't compare equal. This should not be a problem in real + // r-a session, only in tests, because in real r-a we only guess the crate on syntactic-only + // (e.g. on-enter) handlers. The rest pick the `EditionedFileId` from the def map. + let Some(file_id) = src.file_id.file_id() else { + continue; + }; + if file_id.file_id(self) != position.file_id.file_id(self) { continue; } @@ -230,7 +238,15 @@ impl TestDB { let mut fn_def = None; for (_, module) in def_map.modules() { let file_id = module.definition_source(self).file_id; - if file_id != position.file_id { + // We're not comparing the `base_db::EditionedFileId`, but rather the VFS `FileId`, because + // `position.file_id` is created before the def map, causing it to have to wrong crate + // attached often, which means it won't compare equal. This should not be a problem in real + // r-a session, only in tests, because in real r-a we only guess the crate on syntactic-only + // (e.g. on-enter) handlers. The rest pick the `EditionedFileId` from the def map. + let Some(file_id) = file_id.file_id() else { + continue; + }; + if file_id.file_id(self) != position.file_id.file_id(self) { continue; } for decl in module.scope.declarations() { @@ -253,26 +269,25 @@ impl TestDB { }; if size != Some(new_size) { size = Some(new_size); - fn_def = Some(it); + fn_def = Some((it, file_id)); } } } } // Find the innermost block expression that has a `DefMap`. - let def_with_body = fn_def?.into(); + let (def_with_body, file_id) = fn_def?; + let def_with_body = def_with_body.into(); let source_map = self.body_with_source_map(def_with_body).1; let scopes = self.expr_scopes(def_with_body); - let root_syntax_node = self.parse(position.file_id).syntax_node(); + let root_syntax_node = self.parse(file_id).syntax_node(); let scope_iter = algo::ancestors_at_offset(&root_syntax_node, position.offset).filter_map(|node| { let block = ast::BlockExpr::cast(node)?; let expr = ast::Expr::from(block); - let expr_id = source_map - .node_expr(InFile::new(position.file_id.into(), &expr))? - .as_expr() - .unwrap(); + let expr_id = + source_map.node_expr(InFile::new(file_id.into(), &expr))?.as_expr().unwrap(); let scope = scopes.scope_for(expr_id).unwrap(); Some(scope) }); @@ -303,8 +318,7 @@ impl TestDB { // This is pretty horrible, but `Debug` is the only way to inspect // QueryDescriptor at the moment. salsa::EventKind::WillExecute { database_key } => { - let ingredient = self - .as_dyn_database() + let ingredient = (self as &dyn salsa::Database) .ingredient_debug_name(database_key.ingredient_index()); Some(ingredient.to_string()) } |