Assign base text language earlier to fix missing highlighting in deletion hunks (#24413)

Release Notes:

- Fixed deletion diff hunks not being syntax highlighted in some cases

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Cole Miller 2025-02-06 19:14:47 -05:00 committed by GitHub
parent 5315d38cf4
commit 59bba2a98c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 32 deletions

View file

@ -5776,6 +5776,9 @@ async fn test_uncommitted_diff_for_buffer(cx: &mut gpui::TestAppContext) {
);
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
let language_registry = project.read_with(cx, |project, _| project.languages().clone());
let language = rust_lang();
language_registry.add(language.clone());
let buffer = project
.update(cx, |project, cx| {
@ -5790,13 +5793,23 @@ async fn test_uncommitted_diff_for_buffer(cx: &mut gpui::TestAppContext) {
.await
.unwrap();
uncommitted_diff.read_with(cx, |diff, _| {
assert_eq!(
diff.snapshot
.base_text
.as_ref()
.and_then(|base| base.language().cloned()),
Some(language)
)
});
cx.run_until_parked();
uncommitted_diff.update(cx, |uncommitted_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
uncommitted_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&uncommitted_diff.snapshot.base_text.as_ref().unwrap().text(),
&uncommitted_diff.base_text_string().unwrap(),
&[
(0..1, "", "// print goodbye\n"),
(