Remove old project search code path, bump min-supported zed version for collaboration (#18404)

Release Notes:

- N/A
This commit is contained in:
Max Brunsfeld 2024-09-26 12:10:39 -07:00 committed by GitHub
parent 71da81c743
commit c1a039a5d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 157 deletions

View File

@ -474,9 +474,6 @@ impl Server {
.add_request_handler(user_handler(
forward_read_only_project_request::<proto::GetReferences>,
))
.add_request_handler(user_handler(
forward_read_only_project_request::<proto::SearchProject>,
))
.add_request_handler(user_handler(forward_find_search_candidates_request))
.add_request_handler(user_handler(
forward_read_only_project_request::<proto::GetDocumentHighlights>,
@ -2298,7 +2295,7 @@ async fn list_remote_directory(
let dev_server_connection_id = session
.connection_pool()
.await
.dev_server_connection_id_supporting(dev_server_id, ZedVersion::with_list_directory())?;
.online_dev_server_connection_id(dev_server_id)?;
session
.db()
@ -2337,10 +2334,7 @@ async fn update_dev_server_project(
let dev_server_connection_id = session
.connection_pool()
.await
.dev_server_connection_id_supporting(
dev_server_project.dev_server_id,
ZedVersion::with_list_directory(),
)?;
.online_dev_server_connection_id(dev_server_project.dev_server_id)?;
session.peer.send(
dev_server_connection_id,
@ -2950,40 +2944,6 @@ async fn forward_find_search_candidates_request(
.await
.host_for_read_only_project_request(project_id, session.connection_id, session.user_id())
.await?;
let host_version = session
.connection_pool()
.await
.connection(host_connection_id)
.map(|c| c.zed_version);
if host_version.is_some_and(|host_version| host_version < ZedVersion::with_search_candidates())
{
let query = request.query.ok_or_else(|| anyhow!("missing query"))?;
let search = proto::SearchProject {
project_id: project_id.to_proto(),
query: query.query,
regex: query.regex,
whole_word: query.whole_word,
case_sensitive: query.case_sensitive,
files_to_include: query.files_to_include,
files_to_exclude: query.files_to_exclude,
include_ignored: query.include_ignored,
};
let payload = session
.peer
.forward_request(session.connection_id, host_connection_id, search)
.await?;
return response.send(proto::FindSearchCandidatesResponse {
buffer_ids: payload
.locations
.into_iter()
.map(|loc| loc.buffer_id)
.collect(),
});
}
let payload = session
.peer
.forward_request(session.connection_id, host_connection_id, request)

View File

@ -32,15 +32,7 @@ impl fmt::Display for ZedVersion {
impl ZedVersion {
pub fn can_collaborate(&self) -> bool {
self.0 >= SemanticVersion::new(0, 134, 0)
}
pub fn with_list_directory() -> ZedVersion {
ZedVersion(SemanticVersion::new(0, 145, 0))
}
pub fn with_search_candidates() -> ZedVersion {
ZedVersion(SemanticVersion::new(0, 151, 0))
self.0 >= SemanticVersion::new(0, 151, 0)
}
}
@ -169,6 +161,16 @@ impl ConnectionPool {
self.connected_dev_servers.get(&dev_server_id).copied()
}
pub fn online_dev_server_connection_id(
&self,
dev_server_id: DevServerId,
) -> Result<ConnectionId> {
match self.connected_dev_servers.get(&dev_server_id) {
Some(cid) => Ok(*cid),
None => Err(anyhow!(proto::ErrorCode::DevServerOffline)),
}
}
pub fn dev_server_connection_id_supporting(
&self,
dev_server_id: DevServerId,

View File

@ -558,7 +558,6 @@ impl Project {
client.add_model_message_handler(Self::handle_update_worktree);
client.add_model_request_handler(Self::handle_synchronize_buffers);
client.add_model_request_handler(Self::handle_search_project);
client.add_model_request_handler(Self::handle_search_candidate_buffers);
client.add_model_request_handler(Self::handle_open_buffer_by_id);
client.add_model_request_handler(Self::handle_open_buffer_by_path);
@ -2692,9 +2691,9 @@ impl Project {
let (result_tx, result_rx) = smol::channel::unbounded();
let matching_buffers_rx = if query.is_opened_only() {
self.sort_candidate_buffers(&query, cx)
self.sort_search_candidates(&query, cx)
} else {
self.search_for_candidate_buffers(&query, MAX_SEARCH_RESULT_FILES + 1, cx)
self.find_search_candidate_buffers(&query, MAX_SEARCH_RESULT_FILES + 1, cx)
};
cx.spawn(|_, cx| async move {
@ -2757,7 +2756,7 @@ impl Project {
result_rx
}
fn search_for_candidate_buffers(
fn find_search_candidate_buffers(
&mut self,
query: &SearchQuery,
limit: usize,
@ -2769,11 +2768,11 @@ impl Project {
buffer_store.find_search_candidates(query, limit, fs, cx)
})
} else {
self.search_for_candidate_buffers_remote(query, limit, cx)
self.find_search_candidates_remote(query, limit, cx)
}
}
fn sort_candidate_buffers(
fn sort_search_candidates(
&mut self,
search_query: &SearchQuery,
cx: &mut ModelContext<Project>,
@ -2815,7 +2814,7 @@ impl Project {
rx
}
fn search_for_candidate_buffers_remote(
fn find_search_candidates_remote(
&mut self,
query: &SearchQuery,
limit: usize,
@ -3656,46 +3655,6 @@ impl Project {
Ok(proto::TaskTemplatesResponse { templates })
}
async fn handle_search_project(
this: Model<Self>,
envelope: TypedEnvelope<proto::SearchProject>,
mut cx: AsyncAppContext,
) -> Result<proto::SearchProjectResponse> {
let peer_id = envelope.original_sender_id()?;
let query = SearchQuery::from_proto_v1(envelope.payload)?;
let mut result = this.update(&mut cx, |this, cx| this.search(query, cx))?;
cx.spawn(move |mut cx| async move {
let mut locations = Vec::new();
let mut limit_reached = false;
while let Some(result) = result.next().await {
match result {
SearchResult::Buffer { buffer, ranges } => {
for range in ranges {
let start = serialize_anchor(&range.start);
let end = serialize_anchor(&range.end);
let buffer_id = this.update(&mut cx, |this, cx| {
this.create_buffer_for_peer(&buffer, peer_id, cx).into()
})?;
locations.push(proto::Location {
buffer_id,
start: Some(start),
end: Some(end),
});
}
}
SearchResult::LimitReached => limit_reached = true,
}
}
Ok(proto::SearchProjectResponse {
locations,
limit_reached,
// will restart
})
})
.await
}
async fn handle_search_candidate_buffers(
this: Model<Self>,
envelope: TypedEnvelope<proto::FindSearchCandidates>,
@ -3709,7 +3668,7 @@ impl Project {
.ok_or_else(|| anyhow!("missing query field"))?,
)?;
let mut results = this.update(&mut cx, |this, cx| {
this.search_for_candidate_buffers(&query, message.limit as _, cx)
this.find_search_candidate_buffers(&query, message.limit as _, cx)
})?;
let mut response = proto::FindSearchCandidatesResponse {

View File

@ -147,30 +147,6 @@ impl SearchQuery {
})
}
pub fn from_proto_v1(message: proto::SearchProject) -> Result<Self> {
if message.regex {
Self::regex(
message.query,
message.whole_word,
message.case_sensitive,
message.include_ignored,
deserialize_path_matches(&message.files_to_include)?,
deserialize_path_matches(&message.files_to_exclude)?,
None,
)
} else {
Self::text(
message.query,
message.whole_word,
message.case_sensitive,
message.include_ignored,
deserialize_path_matches(&message.files_to_include)?,
deserialize_path_matches(&message.files_to_exclude)?,
None,
)
}
}
pub fn from_proto(message: proto::SearchQuery) -> Result<Self> {
if message.regex {
Self::regex(
@ -194,6 +170,7 @@ impl SearchQuery {
)
}
}
pub fn with_replacement(mut self, new_replacement: String) -> Self {
match self {
Self::Text {
@ -209,18 +186,6 @@ impl SearchQuery {
}
}
}
pub fn to_protov1(&self, project_id: u64) -> proto::SearchProject {
proto::SearchProject {
project_id,
query: self.as_str().to_string(),
regex: self.is_regex(),
whole_word: self.whole_word(),
case_sensitive: self.case_sensitive(),
include_ignored: self.include_ignored(),
files_to_include: self.files_to_include().sources().join(","),
files_to_exclude: self.files_to_exclude().sources().join(","),
}
}
pub fn to_proto(&self) -> proto::SearchQuery {
proto::SearchQuery {

View File

@ -108,8 +108,6 @@ message Envelope {
PrepareRenameResponse prepare_rename_response = 84;
PerformRename perform_rename = 85;
PerformRenameResponse perform_rename_response = 86;
SearchProject search_project = 87;
SearchProjectResponse search_project_response = 88;
UpdateContacts update_contacts = 89;
UpdateInviteInfo update_invite_info = 90;
@ -287,6 +285,7 @@ message Envelope {
CheckFileExistsResponse check_file_exists_response = 256; // current max
}
reserved 87 to 88;
reserved 158 to 161;
reserved 166 to 169;
reserved 224 to 229;
@ -1238,22 +1237,6 @@ message PerformRenameResponse {
ProjectTransaction transaction = 2;
}
message SearchProject {
uint64 project_id = 1;
string query = 2;
bool regex = 3;
bool whole_word = 4;
bool case_sensitive = 5;
string files_to_include = 6;
string files_to_exclude = 7;
bool include_ignored = 8;
}
message SearchProjectResponse {
repeated Location locations = 1;
bool limit_reached = 2;
}
message SearchQuery {
string query = 2;
bool regex = 3;

View File

@ -279,8 +279,6 @@ messages!(
(SaveBuffer, Foreground),
(SetChannelMemberRole, Foreground),
(SetChannelVisibility, Foreground),
(SearchProject, Background),
(SearchProjectResponse, Background),
(SendChannelMessage, Background),
(SendChannelMessageResponse, Background),
(ShareProject, Foreground),
@ -454,7 +452,6 @@ request_messages!(
(RespondToChannelInvite, Ack),
(RespondToContactRequest, Ack),
(SaveBuffer, BufferSaved),
(SearchProject, SearchProjectResponse),
(FindSearchCandidates, FindSearchCandidatesResponse),
(SendChannelMessage, SendChannelMessageResponse),
(SetChannelMemberRole, Ack),
@ -541,7 +538,6 @@ entity_messages!(
ResolveCompletionDocumentation,
ResolveInlayHint,
SaveBuffer,
SearchProject,
StartLanguageServer,
SynchronizeBuffers,
TaskContextForLocation,