initial outline for rate limiting status updates

This commit is contained in:
KCaverly 2023-09-08 12:35:15 -04:00
parent e9747d0fea
commit a5ee8fc805
4 changed files with 106 additions and 8 deletions

View file

@ -91,10 +91,7 @@ pub fn init(
let semantic_index = SemanticIndex::new(
fs,
db_file_path,
Arc::new(OpenAIEmbeddings {
client: http_client,
executor: cx.background(),
}),
Arc::new(OpenAIEmbeddings::new(http_client, cx.background())),
language_registry,
cx.clone(),
)
@ -113,7 +110,10 @@ pub fn init(
pub enum SemanticIndexStatus {
NotIndexed,
Indexed,
Indexing { remaining_files: usize },
Indexing {
remaining_files: usize,
rate_limiting: Duration,
},
}
pub struct SemanticIndex {
@ -132,6 +132,8 @@ struct ProjectState {
pending_file_count_rx: watch::Receiver<usize>,
pending_file_count_tx: Arc<Mutex<watch::Sender<usize>>>,
pending_index: usize,
rate_limiting_count_rx: watch::Receiver<usize>,
rate_limiting_count_tx: Arc<Mutex<watch::Sender<usize>>>,
_subscription: gpui::Subscription,
_observe_pending_file_count: Task<()>,
}
@ -223,11 +225,15 @@ impl ProjectState {
fn new(subscription: gpui::Subscription, cx: &mut ModelContext<SemanticIndex>) -> Self {
let (pending_file_count_tx, pending_file_count_rx) = watch::channel_with(0);
let pending_file_count_tx = Arc::new(Mutex::new(pending_file_count_tx));
let (rate_limiting_count_tx, rate_limiting_count_rx) = watch::channel_with(0);
let rate_limiting_count_tx = Arc::new(Mutex::new(rate_limiting_count_tx));
Self {
worktrees: Default::default(),
pending_file_count_rx: pending_file_count_rx.clone(),
pending_file_count_tx,
pending_index: 0,
rate_limiting_count_rx: rate_limiting_count_rx.clone(),
rate_limiting_count_tx,
_subscription: subscription,
_observe_pending_file_count: cx.spawn_weak({
let mut pending_file_count_rx = pending_file_count_rx.clone();
@ -293,6 +299,7 @@ impl SemanticIndex {
} else {
SemanticIndexStatus::Indexing {
remaining_files: project_state.pending_file_count_rx.borrow().clone(),
rate_limiting: self.embedding_provider.rate_limit_expiration(),
}
}
} else {