
Fixes an issue that caused Windows to fail when removing extension's directories, as Zed had never stop any related processes. Now: * Zed shuts down and waits until the end when the language servers are shut down * Adds `impl Drop for WasmExtension` where does `self.tx.close_channel();` to stop a receiver loop that holds the "lock" on the extension's work dir. The extension was dropped, but the channel was not closed for some reason. * Does more unregistration to ensure `Arc<WasmExtension>` with the `tx` does not leak further * Tidies up the related errors which had never reported a problematic path before Release Notes: - N/A --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com> Co-authored-by: Smit <smit@zed.dev>
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use std::sync::Arc;
|
|
|
|
use collections::HashMap;
|
|
use gpui::{App, BackgroundExecutor, Global, ReadGlobal, UpdateGlobal};
|
|
use parking_lot::RwLock;
|
|
|
|
use crate::{IndexedDocsProvider, IndexedDocsStore, ProviderId};
|
|
|
|
struct GlobalIndexedDocsRegistry(Arc<IndexedDocsRegistry>);
|
|
|
|
impl Global for GlobalIndexedDocsRegistry {}
|
|
|
|
pub struct IndexedDocsRegistry {
|
|
executor: BackgroundExecutor,
|
|
stores_by_provider: RwLock<HashMap<ProviderId, Arc<IndexedDocsStore>>>,
|
|
}
|
|
|
|
impl IndexedDocsRegistry {
|
|
pub fn global(cx: &App) -> Arc<Self> {
|
|
GlobalIndexedDocsRegistry::global(cx).0.clone()
|
|
}
|
|
|
|
pub(crate) fn init_global(cx: &mut App) {
|
|
GlobalIndexedDocsRegistry::set_global(
|
|
cx,
|
|
GlobalIndexedDocsRegistry(Arc::new(Self::new(cx.background_executor().clone()))),
|
|
);
|
|
}
|
|
|
|
pub fn new(executor: BackgroundExecutor) -> Self {
|
|
Self {
|
|
executor,
|
|
stores_by_provider: RwLock::new(HashMap::default()),
|
|
}
|
|
}
|
|
|
|
pub fn list_providers(&self) -> Vec<ProviderId> {
|
|
self.stores_by_provider
|
|
.read()
|
|
.keys()
|
|
.cloned()
|
|
.collect::<Vec<_>>()
|
|
}
|
|
|
|
pub fn register_provider(
|
|
&self,
|
|
provider: Box<dyn IndexedDocsProvider + Send + Sync + 'static>,
|
|
) {
|
|
self.stores_by_provider.write().insert(
|
|
provider.id(),
|
|
Arc::new(IndexedDocsStore::new(provider, self.executor.clone())),
|
|
);
|
|
}
|
|
|
|
pub fn unregister_provider(&self, provider_id: &ProviderId) {
|
|
self.stores_by_provider.write().remove(provider_id);
|
|
}
|
|
|
|
pub fn get_provider_store(&self, provider_id: ProviderId) -> Option<Arc<IndexedDocsStore>> {
|
|
self.stores_by_provider.read().get(&provider_id).cloned()
|
|
}
|
|
}
|