mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 21:25:25 +00:00
internal: don't panic when the crate graph isn't ready #19351
This commit is contained in:
parent
3fc655b239
commit
788232b355
14 changed files with 50 additions and 30 deletions
|
|
@ -314,11 +314,11 @@ impl<'db> SemanticsImpl<'db> {
|
|||
tree
|
||||
}
|
||||
|
||||
/// If not crate is found for the file, returns the last crate in topological order.
|
||||
pub fn first_crate_or_default(&self, file: FileId) -> Crate {
|
||||
/// If not crate is found for the file, try to return the last crate in topological order.
|
||||
pub fn first_crate(&self, file: FileId) -> Option<Crate> {
|
||||
match self.file_to_module_defs(file).next() {
|
||||
Some(module) => module.krate(),
|
||||
None => (*self.db.all_crates().last().unwrap()).into(),
|
||||
Some(module) => Some(module.krate()),
|
||||
None => self.db.all_crates().last().copied().map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,10 @@ impl<'a> SymbolCollector<'a> {
|
|||
symbols: Default::default(),
|
||||
work: Default::default(),
|
||||
current_container_name: None,
|
||||
display_target: DisplayTarget::from_crate(db, *db.all_crates().last().unwrap()),
|
||||
display_target: DisplayTarget::from_crate(
|
||||
db,
|
||||
*db.all_crates().last().expect("no crate graph present"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue