Start work on genericizing /rustdoc
(#13745)
This PR begins the process of making the backing infrastructure for the `/rustdoc` command more generic such that it can be applied to additional documentation providers. In this PR we: - Rename the `rustdoc` crate to `indexed_docs` as a more general-purpose name - Start moving rustdoc-specific functionality into `indexed_docs::providers::rustdoc` - Add an `IndexedDocsRegistry` to hold multiple `IndexedDocsStore`s (one per provider) We haven't yet removed the rustdoc-specific bits in the `DocsIndexer`. That will follow soon. Release Notes: - N/A
This commit is contained in:
parent
eab98eb9c9
commit
7460381285
18 changed files with 425 additions and 355 deletions
47
crates/indexed_docs/src/registry.rs
Normal file
47
crates/indexed_docs/src/registry.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use collections::HashMap;
|
||||
use gpui::{AppContext, BackgroundExecutor, Global, ReadGlobal, UpdateGlobal};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::{IndexedDocsStore, Provider, 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: &AppContext) -> Arc<Self> {
|
||||
GlobalIndexedDocsRegistry::global(cx).0.clone()
|
||||
}
|
||||
|
||||
pub fn init_global(cx: &mut AppContext) {
|
||||
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 register_provider(&self, provider: Provider) {
|
||||
self.stores_by_provider.write().insert(
|
||||
provider.id.clone(),
|
||||
Arc::new(IndexedDocsStore::new(provider, self.executor.clone())),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn get_provider_store(&self, provider_id: ProviderId) -> Option<Arc<IndexedDocsStore>> {
|
||||
self.stores_by_provider.read().get(&provider_id).cloned()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue