/auto (#16696)
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>
This commit is contained in:
parent
93a3e8bc94
commit
91ffa02e2c
42 changed files with 2776 additions and 1054 deletions
49
crates/semantic_index/src/indexing.rs
Normal file
49
crates/semantic_index/src/indexing.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue