language: Only block the foreground on buffer reparsing when necessary (#43888)

Gist is we only need to block the foreground thread for reparsing if
immediate language changes are useful to the user. That is usually only
the case when they edit the buffer

Release Notes:

- Improved performance of large project searches and project diffs

Co-authored by: David Kleingeld <david@zed.dev>
This commit is contained in:
Lukas Wirth
2025-12-01 14:57:15 +01:00
committed by GitHub
parent 3969109aa3
commit 9af6e82e65
54 changed files with 363 additions and 250 deletions
+7 -4
View File
@@ -684,8 +684,9 @@ impl LocalBufferStore {
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))?;
let buffer = cx.new(|cx| {
Buffer::local("", cx).with_language_immediate(language::PLAIN_TEXT.clone(), cx)
})?;
buffer_store.update(cx, |buffer_store, cx| {
buffer_store.add_buffer(buffer.clone(), cx).log_err();
if !project_searchable {
@@ -1591,8 +1592,10 @@ impl BufferStore {
cx: &mut Context<Self>,
) -> Entity<Buffer> {
let buffer = cx.new(|cx| {
Buffer::local(text, cx)
.with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx)
Buffer::local(text, cx).with_language_immediate(
language.unwrap_or_else(|| language::PLAIN_TEXT.clone()),
cx,
)
});
self.add_buffer(buffer.clone(), cx).log_err();
+2 -2
View File
@@ -3885,7 +3885,7 @@ impl Repository {
let git_commit_language =
language_registry.language_for_name("Git Commit").await?;
buffer.update(&mut cx, |buffer, cx| {
buffer.set_language(Some(git_commit_language), cx);
buffer.set_language_immediate(Some(git_commit_language), cx);
})?;
}
this.update(&mut cx, |this, _| {
@@ -3912,7 +3912,7 @@ impl Repository {
if let Some(language_registry) = language_registry {
let git_commit_language = language_registry.language_for_name("Git Commit").await?;
buffer.update(cx, |buffer, cx| {
buffer.set_language(Some(git_commit_language), cx);
buffer.set_language_immediate(Some(git_commit_language), cx);
})?;
}
+1 -1
View File
@@ -4353,7 +4353,7 @@ impl LspStore {
}
for buffer in buffers_with_unknown_injections {
buffer.update(cx, |buffer, cx| buffer.reparse(cx));
buffer.update(cx, |buffer, cx| buffer.reparse(cx, false));
}
})
.ok();