Unnamed repository; edit this file 'description' to name the repository.
internal: Improve panic message when FileSourceRootInput is missing
I'm seeing several occurrences of errors of the form:
```
Unable to get `FileSourceRootInput` with `vfs::FileId` (FileId(22452)); this is a bug
```
I suspect it occurs when the user has many projects open, but I can't
reliably reproduce yet. In the meantime, include the actual file name
to aid debugging.
AI disclosure: Partially written with Codex and GPT 5.5.
| -rw-r--r-- | crates/base-db/src/lib.rs | 20 | ||||
| -rw-r--r-- | crates/hir-def/src/test_db.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/test_db.rs | 2 | ||||
| -rw-r--r-- | crates/ide-db/src/lib.rs | 2 |
4 files changed, 21 insertions, 5 deletions
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index ff439119c9..a681ac72b7 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -170,16 +170,32 @@ impl Files { }; } - pub fn file_source_root(&self, id: vfs::FileId) -> FileSourceRootInput { + pub fn file_source_root( + &self, + db: &dyn SourceDatabase, + id: vfs::FileId, + ) -> FileSourceRootInput { let file_source_root = match self.file_source_roots.get(&id) { Some(file_source_root) => file_source_root, None => panic!( - "Unable to get `FileSourceRootInput` with `vfs::FileId` ({id:?}); this is a bug", + "Unable to get `FileSourceRootInput` with `vfs::FileId` ({id:?}, path: {}); this is a bug", + self.path_for_file(db, id) + .map_or_else(|| "<unknown>".to_owned(), |path| path.to_string()), ), }; *file_source_root } + fn path_for_file(&self, db: &dyn SourceDatabase, id: vfs::FileId) -> Option<vfs::VfsPath> { + for source_root in &*self.source_roots { + let source_root = *source_root.value(); + if let Some(path) = source_root.source_root(db).path_for_file(&id) { + return Some(path.clone()); + } + } + None + } + pub fn set_file_source_root_with_durability( &self, db: &mut dyn SourceDatabase, diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs index 913b99223d..e3fd4560f0 100644 --- a/crates/hir-def/src/test_db.rs +++ b/crates/hir-def/src/test_db.rs @@ -122,7 +122,7 @@ impl SourceDatabase for TestDB { } fn file_source_root(&self, id: base_db::FileId) -> FileSourceRootInput { - self.files.file_source_root(id) + self.files.file_source_root(self, id) } fn set_file_source_root_with_durability( diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs index 653fbe34f1..3dee592dbc 100644 --- a/crates/hir-ty/src/test_db.rs +++ b/crates/hir-ty/src/test_db.rs @@ -112,7 +112,7 @@ impl SourceDatabase for TestDB { } fn file_source_root(&self, id: base_db::FileId) -> FileSourceRootInput { - self.files.file_source_root(id) + self.files.file_source_root(self, id) } fn set_file_source_root_with_durability( diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 2b1525e2b2..87cbc7c533 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -160,7 +160,7 @@ impl SourceDatabase for RootDatabase { } fn file_source_root(&self, id: vfs::FileId) -> FileSourceRootInput { - self.files.file_source_root(id) + self.files.file_source_root(self, id) } fn set_file_source_root_with_durability( |