SSH remote search (#16915)

Co-Authored-By: Max <max@zed.dev>

Release Notes:

- ssh remoting: add project search

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Conrad Irwin 2024-08-26 14:47:02 -06:00 committed by GitHub
parent 0332eaf797
commit ef22372f0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 866 additions and 572 deletions

View file

@ -1,8 +1,9 @@
use anyhow::Result;
use anyhow::{anyhow, Result};
use fs::Fs;
use gpui::{AppContext, AsyncAppContext, Context, Model, ModelContext};
use project::{
buffer_store::{BufferStore, BufferStoreEvent},
search::SearchQuery,
worktree_store::WorktreeStore,
ProjectPath, WorktreeId, WorktreeSettings,
};
@ -49,6 +50,7 @@ impl HeadlessProject {
session.add_request_handler(this.clone(), Self::handle_list_remote_directory);
session.add_request_handler(this.clone(), Self::handle_add_worktree);
session.add_request_handler(this.clone(), Self::handle_open_buffer_by_path);
session.add_request_handler(this.clone(), Self::handle_find_search_candidates);
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_blame_buffer);
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_update_buffer);
@ -160,6 +162,49 @@ impl HeadlessProject {
})
}
pub async fn handle_find_search_candidates(
this: Model<Self>,
envelope: TypedEnvelope<proto::FindSearchCandidates>,
mut cx: AsyncAppContext,
) -> Result<proto::FindSearchCandidatesResponse> {
let message = envelope.payload;
let query = SearchQuery::from_proto(
message
.query
.ok_or_else(|| anyhow!("missing query field"))?,
)?;
let mut results = this.update(&mut cx, |this, cx| {
this.buffer_store.update(cx, |buffer_store, cx| {
buffer_store.find_search_candidates(&query, message.limit as _, this.fs.clone(), cx)
})
})?;
let mut response = proto::FindSearchCandidatesResponse {
buffer_ids: Vec::new(),
};
let (buffer_store, client) = this.update(&mut cx, |this, _| {
(this.buffer_store.clone(), this.session.clone())
})?;
while let Some(buffer) = results.next().await {
let buffer_id = buffer.update(&mut cx, |this, _| this.remote_id())?;
response.buffer_ids.push(buffer_id.to_proto());
BufferStore::create_buffer_for_peer(
buffer_store.clone(),
PEER_ID,
buffer_id,
PROJECT_ID,
client.clone(),
&mut cx,
)
.await?;
}
Ok(response)
}
pub async fn handle_list_remote_directory(
this: Model<Self>,
envelope: TypedEnvelope<proto::ListRemoteDirectory>,