project: Be explicit about project-searchability for buffers (#37773)
Closes https://github.com/zed-industries/zed/issues/28830 Release Notes: - Fixed builtin buffers and log views showing up in project search
This commit is contained in:
@@ -319,7 +319,11 @@ impl RemoteBufferStore {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_buffer(&self, cx: &mut Context<BufferStore>) -> Task<Result<Entity<Buffer>>> {
|
||||
fn create_buffer(
|
||||
&self,
|
||||
project_searchable: bool,
|
||||
cx: &mut Context<BufferStore>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
let create = self.upstream_client.request(proto::OpenNewBuffer {
|
||||
project_id: self.project_id,
|
||||
});
|
||||
@@ -327,8 +331,13 @@ impl RemoteBufferStore {
|
||||
let response = create.await?;
|
||||
let buffer_id = BufferId::new(response.buffer_id)?;
|
||||
|
||||
this.update(cx, |this, cx| this.wait_for_remote_buffer(buffer_id, cx))?
|
||||
.await
|
||||
this.update(cx, |this, cx| {
|
||||
if !project_searchable {
|
||||
this.non_searchable_buffers.insert(buffer_id);
|
||||
}
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await
|
||||
})
|
||||
}
|
||||
|
||||
@@ -670,12 +679,21 @@ impl LocalBufferStore {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_buffer(&self, cx: &mut Context<BufferStore>) -> Task<Result<Entity<Buffer>>> {
|
||||
fn create_buffer(
|
||||
&self,
|
||||
project_searchable: bool,
|
||||
cx: &mut Context<BufferStore>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
cx.spawn(async move |buffer_store, cx| {
|
||||
let buffer =
|
||||
cx.new(|cx| Buffer::local("", cx).with_language(language::PLAIN_TEXT.clone(), cx))?;
|
||||
buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.add_buffer(buffer.clone(), cx).log_err();
|
||||
if !project_searchable {
|
||||
buffer_store
|
||||
.non_searchable_buffers
|
||||
.insert(buffer.read(cx).remote_id());
|
||||
}
|
||||
})?;
|
||||
Ok(buffer)
|
||||
})
|
||||
@@ -848,10 +866,14 @@ impl BufferStore {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_buffer(&mut self, cx: &mut Context<Self>) -> Task<Result<Entity<Buffer>>> {
|
||||
pub fn create_buffer(
|
||||
&mut self,
|
||||
project_searchable: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
match &self.state {
|
||||
BufferStoreState::Local(this) => this.create_buffer(cx),
|
||||
BufferStoreState::Remote(this) => this.create_buffer(cx),
|
||||
BufferStoreState::Local(this) => this.create_buffer(project_searchable, cx),
|
||||
BufferStoreState::Remote(this) => this.create_buffer(project_searchable, cx),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1610,6 +1632,7 @@ impl BufferStore {
|
||||
&mut self,
|
||||
text: &str,
|
||||
language: Option<Arc<Language>>,
|
||||
project_searchable: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Entity<Buffer> {
|
||||
let buffer = cx.new(|cx| {
|
||||
@@ -1619,6 +1642,9 @@ impl BufferStore {
|
||||
|
||||
self.add_buffer(buffer.clone(), cx).log_err();
|
||||
let buffer_id = buffer.read(cx).remote_id();
|
||||
if !project_searchable {
|
||||
self.non_searchable_buffers.insert(buffer_id);
|
||||
}
|
||||
|
||||
if let Some(file) = File::from_dyn(buffer.read(cx).file()) {
|
||||
self.path_to_buffer_id.insert(
|
||||
@@ -1688,10 +1714,6 @@ impl BufferStore {
|
||||
}
|
||||
serialized_transaction
|
||||
}
|
||||
|
||||
pub(crate) fn mark_buffer_as_non_searchable(&mut self, buffer_id: BufferId) {
|
||||
self.non_searchable_buffers.insert(buffer_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl OpenBuffer {
|
||||
|
||||
@@ -3317,7 +3317,7 @@ impl Repository {
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
cx.spawn(async move |repository, cx| {
|
||||
let buffer = buffer_store
|
||||
.update(cx, |buffer_store, cx| buffer_store.create_buffer(cx))?
|
||||
.update(cx, |buffer_store, cx| buffer_store.create_buffer(false, cx))?
|
||||
.await?;
|
||||
|
||||
if let Some(language_registry) = language_registry {
|
||||
|
||||
@@ -2540,22 +2540,28 @@ impl Project {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_buffer(&mut self, cx: &mut Context<Self>) -> Task<Result<Entity<Buffer>>> {
|
||||
self.buffer_store
|
||||
.update(cx, |buffer_store, cx| buffer_store.create_buffer(cx))
|
||||
pub fn create_buffer(
|
||||
&mut self,
|
||||
searchable: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
self.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.create_buffer(searchable, cx)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_local_buffer(
|
||||
&mut self,
|
||||
text: &str,
|
||||
language: Option<Arc<Language>>,
|
||||
project_searchable: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Entity<Buffer> {
|
||||
if self.is_via_collab() || self.is_via_remote_server() {
|
||||
panic!("called create_local_buffer on a remote project")
|
||||
}
|
||||
self.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.create_local_buffer(text, language, cx)
|
||||
buffer_store.create_local_buffer(text, language, project_searchable, cx)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4913,7 +4919,7 @@ impl Project {
|
||||
mut cx: AsyncApp,
|
||||
) -> Result<proto::OpenBufferResponse> {
|
||||
let buffer = this
|
||||
.update(&mut cx, |this, cx| this.create_buffer(cx))?
|
||||
.update(&mut cx, |this, cx| this.create_buffer(true, cx))?
|
||||
.await?;
|
||||
let peer_id = envelope.original_sender_id()?;
|
||||
|
||||
@@ -5244,12 +5250,6 @@ impl Project {
|
||||
pub fn agent_location(&self) -> Option<AgentLocation> {
|
||||
self.agent_location.clone()
|
||||
}
|
||||
|
||||
pub fn mark_buffer_as_non_searchable(&self, buffer_id: BufferId, cx: &mut Context<Project>) {
|
||||
self.buffer_store.update(cx, |buffer_store, _| {
|
||||
buffer_store.mark_buffer_as_non_searchable(buffer_id)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PathMatchCandidateSet {
|
||||
|
||||
@@ -3876,7 +3876,7 @@ async fn test_save_file_spawns_language_server(cx: &mut gpui::TestAppContext) {
|
||||
);
|
||||
|
||||
let buffer = project
|
||||
.update(cx, |this, cx| this.create_buffer(cx))
|
||||
.update(cx, |this, cx| this.create_buffer(false, cx))
|
||||
.unwrap()
|
||||
.await;
|
||||
project.update(cx, |this, cx| {
|
||||
@@ -4088,7 +4088,9 @@ async fn test_save_as(cx: &mut gpui::TestAppContext) {
|
||||
let languages = project.update(cx, |project, _| project.languages().clone());
|
||||
languages.add(rust_lang());
|
||||
|
||||
let buffer = project.update(cx, |project, cx| project.create_local_buffer("", None, cx));
|
||||
let buffer = project.update(cx, |project, cx| {
|
||||
project.create_local_buffer("", None, false, cx)
|
||||
});
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit([(0..0, "abc")], None, cx);
|
||||
assert!(buffer.is_dirty());
|
||||
@@ -5585,9 +5587,7 @@ async fn test_search_with_buffer_exclusions(cx: &mut gpui::TestAppContext) {
|
||||
|
||||
let project = Project::test(fs.clone(), [path!("/dir").as_ref()], cx).await;
|
||||
let _buffer = project.update(cx, |project, cx| {
|
||||
let buffer = project.create_local_buffer("file", None, cx);
|
||||
project.mark_buffer_as_non_searchable(buffer.read(cx).remote_id(), cx);
|
||||
buffer
|
||||
project.create_local_buffer("file", None, false, cx)
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user