Fix assignment of language to formerly-untitled buffers

When lazy-loading a language, check if it matches plain text buffers.

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-02-17 11:12:57 -08:00
parent 48b76f96fc
commit 31dac39e34
2 changed files with 35 additions and 10 deletions

View file

@ -2130,6 +2130,20 @@ async fn test_save_as(cx: &mut gpui::TestAppContext) {
fs.insert_tree("/dir", json!({})).await;
let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await;
let languages = project.read_with(cx, |project, _| project.languages().clone());
languages.register(
"/some/path",
LanguageConfig {
name: "Rust".into(),
path_suffixes: vec!["rs".into()],
..Default::default()
},
tree_sitter_rust::language(),
None,
|_| Default::default(),
);
let buffer = project.update(cx, |project, cx| {
project.create_buffer("", None, cx).unwrap()
});
@ -2137,23 +2151,30 @@ async fn test_save_as(cx: &mut gpui::TestAppContext) {
buffer.edit([(0..0, "abc")], None, cx);
assert!(buffer.is_dirty());
assert!(!buffer.has_conflict());
assert_eq!(buffer.language().unwrap().name().as_ref(), "Plain Text");
});
project
.update(cx, |project, cx| {
project.save_buffer_as(buffer.clone(), "/dir/file1".into(), cx)
project.save_buffer_as(buffer.clone(), "/dir/file1.rs".into(), cx)
})
.await
.unwrap();
assert_eq!(fs.load(Path::new("/dir/file1")).await.unwrap(), "abc");
assert_eq!(fs.load(Path::new("/dir/file1.rs")).await.unwrap(), "abc");
cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, cx| {
assert_eq!(buffer.file().unwrap().full_path(cx), Path::new("dir/file1"));
assert_eq!(
buffer.file().unwrap().full_path(cx),
Path::new("dir/file1.rs")
);
assert!(!buffer.is_dirty());
assert!(!buffer.has_conflict());
assert_eq!(buffer.language().unwrap().name().as_ref(), "Rust");
});
let opened_buffer = project
.update(cx, |project, cx| {
project.open_local_buffer("/dir/file1", cx)
project.open_local_buffer("/dir/file1.rs", cx)
})
.await
.unwrap();