fix: deadlock when iterating dependencies (#568)

This commit is contained in:
Myriad-Dreamin 2024-08-27 14:49:58 +08:00 committed by GitHub
parent c6da5590ca
commit 9f9c710906
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 12 deletions

View file

@ -166,7 +166,7 @@ pub trait AnalysisResources {
fn resolve(&self, spec: &PackageSpec) -> Result<Arc<Path>, PackageError>;
/// Get all the files in the workspace.
fn iter_dependencies(&self, f: &mut dyn FnMut(ImmutPath));
fn dependencies(&self) -> EcoVec<ImmutPath>;
/// Resolve extra font information.
fn font_info(&self, _font: Font) -> Option<Arc<DataSource>> {

View file

@ -94,12 +94,11 @@ impl<'a, 'w> ReferencesWorker<'a, 'w> {
fn label_root(mut self) -> Option<Vec<LspLocation>> {
let mut ids = vec![];
// Collect ids first to avoid deadlocks
self.ctx.ctx.resources.iter_dependencies(&mut |path| {
if let Ok(ref_fid) = self.ctx.ctx.file_id_by_path(&path) {
for dep in self.ctx.ctx.resources.dependencies() {
if let Ok(ref_fid) = self.ctx.ctx.file_id_by_path(&dep) {
ids.push(ref_fid);
}
});
}
for ref_fid in ids {
self.file(ref_fid)?;

View file

@ -38,9 +38,9 @@ impl SemanticRequest for SymbolRequest {
// todo! need compilation for iter_dependencies
ctx.resources.iter_dependencies(&mut |path| {
for path in ctx.resources.dependencies() {
let Ok(source) = ctx.source_by_path(&path) else {
return;
continue;
};
let uri = path_to_url(&path).unwrap();
let res =
@ -57,7 +57,7 @@ impl SemanticRequest for SymbolRequest {
if let Some(mut res) = res {
symbols.append(&mut res)
}
});
}
Some(symbols)
}

View file

@ -7,6 +7,7 @@ use std::{
path::{Path, PathBuf},
};
use ecow::EcoVec;
use once_cell::sync::Lazy;
use reflexo_typst::config::CompileOpts;
use reflexo_typst::package::{PackageRegistry, PackageSpec};
@ -40,8 +41,13 @@ impl<'a> AnalysisResources for WrapWorld<'a> {
self.0.registry.resolve(spec)
}
fn iter_dependencies(&self, f: &mut dyn FnMut(reflexo::ImmutPath)) {
self.0.iter_dependencies(f)
fn dependencies(&self) -> EcoVec<reflexo::ImmutPath> {
let mut v = EcoVec::new();
self.0.iter_dependencies(&mut |p| {
v.push(p);
});
v
}
}

View file

@ -215,9 +215,14 @@ impl CompileHandler {
self.0.registry.resolve(spec)
}
fn iter_dependencies(&self, f: &mut dyn FnMut(ImmutPath)) {
fn dependencies(&self) -> EcoVec<ImmutPath> {
use reflexo_typst::WorldDeps;
self.0.iter_dependencies(f)
let mut deps = EcoVec::new();
self.0.iter_dependencies(&mut |dep| {
deps.push(dep);
});
deps
}
/// Resolve extra font information.