
Add `/auto` behind a feature flag that's disabled for now, even for staff. We've decided on a different design for context inference, but there are parts of /auto that will be useful for that, so we want them in the code base even if they're unused for now. Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use collections::HashSet;
|
|
use parking_lot::Mutex;
|
|
use project::ProjectEntryId;
|
|
use smol::channel;
|
|
use std::sync::{Arc, Weak};
|
|
|
|
/// The set of entries that are currently being indexed.
|
|
pub struct IndexingEntrySet {
|
|
entry_ids: Mutex<HashSet<ProjectEntryId>>,
|
|
tx: channel::Sender<()>,
|
|
}
|
|
|
|
/// When dropped, removes the entry from the set of entries that are being indexed.
|
|
#[derive(Clone)]
|
|
pub(crate) struct IndexingEntryHandle {
|
|
entry_id: ProjectEntryId,
|
|
set: Weak<IndexingEntrySet>,
|
|
}
|
|
|
|
impl IndexingEntrySet {
|
|
pub fn new(tx: channel::Sender<()>) -> Self {
|
|
Self {
|
|
entry_ids: Default::default(),
|
|
tx,
|
|
}
|
|
}
|
|
|
|
pub fn insert(self: &Arc<Self>, entry_id: ProjectEntryId) -> IndexingEntryHandle {
|
|
self.entry_ids.lock().insert(entry_id);
|
|
self.tx.send_blocking(()).ok();
|
|
IndexingEntryHandle {
|
|
entry_id,
|
|
set: Arc::downgrade(self),
|
|
}
|
|
}
|
|
|
|
pub fn len(&self) -> usize {
|
|
self.entry_ids.lock().len()
|
|
}
|
|
}
|
|
|
|
impl Drop for IndexingEntryHandle {
|
|
fn drop(&mut self) {
|
|
if let Some(set) = self.set.upgrade() {
|
|
set.tx.send_blocking(()).ok();
|
|
set.entry_ids.lock().remove(&self.entry_id);
|
|
}
|
|
}
|
|
}
|