mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
base-db: add more details to panic
This commit is contained in:
parent
f6dd41e9e2
commit
9e3bbd8acc
1 changed files with 20 additions and 9 deletions
|
|
@ -57,7 +57,12 @@ pub struct Files {
|
||||||
|
|
||||||
impl Files {
|
impl Files {
|
||||||
pub fn file_text(&self, file_id: vfs::FileId) -> FileText {
|
pub fn file_text(&self, file_id: vfs::FileId) -> FileText {
|
||||||
*self.files.get(&file_id).expect("Unable to fetch file; this is a bug")
|
match self.files.get(&file_id) {
|
||||||
|
Some(text) => *text,
|
||||||
|
None => {
|
||||||
|
panic!("Unable to fetch file text for `vfs::FileId`: {:?}; this is a bug", file_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_file_text(&self, db: &mut dyn SourceDatabase, file_id: vfs::FileId, text: &str) {
|
pub fn set_file_text(&self, db: &mut dyn SourceDatabase, file_id: vfs::FileId, text: &str) {
|
||||||
|
|
@ -93,10 +98,13 @@ impl Files {
|
||||||
|
|
||||||
/// Source root of the file.
|
/// Source root of the file.
|
||||||
pub fn source_root(&self, source_root_id: SourceRootId) -> SourceRootInput {
|
pub fn source_root(&self, source_root_id: SourceRootId) -> SourceRootInput {
|
||||||
let source_root = self
|
let source_root = match self.source_roots.get(&source_root_id) {
|
||||||
.source_roots
|
Some(source_root) => source_root,
|
||||||
.get(&source_root_id)
|
None => panic!(
|
||||||
.expect("Unable to fetch source root id; this is a bug");
|
"Unable to fetch `SourceRootInput` with `SourceRootId` ({:?}); this is a bug",
|
||||||
|
source_root_id
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
*source_root
|
*source_root
|
||||||
}
|
}
|
||||||
|
|
@ -121,10 +129,13 @@ impl Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_source_root(&self, id: vfs::FileId) -> FileSourceRootInput {
|
pub fn file_source_root(&self, id: vfs::FileId) -> FileSourceRootInput {
|
||||||
let file_source_root = self
|
let file_source_root = match self.file_source_roots.get(&id) {
|
||||||
.file_source_roots
|
Some(file_source_root) => file_source_root,
|
||||||
.get(&id)
|
None => panic!(
|
||||||
.expect("Unable to fetch FileSourceRootInput; this is a bug");
|
"Unable to get `FileSourceRootInput` with `vfs::FileId` ({:?}); this is a bug",
|
||||||
|
id
|
||||||
|
),
|
||||||
|
};
|
||||||
*file_source_root
|
*file_source_root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue