From 9e6c54ba0cf804bf3d0a414fd4ccc8688fae4a06 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 19 Sep 2021 17:33:46 -0700 Subject: [PATCH] Test language assignment when new buffers are saved --- zed/src/editor/buffer.rs | 4 ++++ zed/src/workspace.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/zed/src/editor/buffer.rs b/zed/src/editor/buffer.rs index 43e5693bd4..82aa10d438 100644 --- a/zed/src/editor/buffer.rs +++ b/zed/src/editor/buffer.rs @@ -801,6 +801,10 @@ impl Buffer { cx.emit(Event::FileHandleChanged); } + pub fn language(&self) -> Option<&Arc> { + self.language.as_ref() + } + pub fn parse_count(&self) -> usize { self.parse_count } diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index ff3666e0de..1a83c35876 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -1476,7 +1476,7 @@ mod tests { }); cx.simulate_new_path_selection(|parent_dir| { assert_eq!(parent_dir, dir.path()); - Some(parent_dir.join("the-new-name")) + Some(parent_dir.join("the-new-name.rs")) }); cx.read(|cx| { assert!(editor.is_dirty(cx)); @@ -1489,8 +1489,10 @@ mod tests { .await; cx.read(|cx| { assert!(!editor.is_dirty(cx)); - assert_eq!(editor.title(cx), "the-new-name"); + assert_eq!(editor.title(cx), "the-new-name.rs"); }); + // The language is assigned based on the path + editor.read_with(&cx, |editor, cx| assert!(editor.language(cx).is_some())); // Edit the file and save it again. This time, there is no filename prompt. editor.update(&mut cx, |editor, cx| { @@ -1504,7 +1506,7 @@ mod tests { editor .condition(&cx, |editor, cx| !editor.is_dirty(cx)) .await; - cx.read(|cx| assert_eq!(editor.title(cx), "the-new-name")); + cx.read(|cx| assert_eq!(editor.title(cx), "the-new-name.rs")); // Open the same newly-created file in another pane item. The new editor should reuse // the same buffer. @@ -1512,7 +1514,7 @@ mod tests { workspace.open_new_file(&OpenNew(app_state.clone()), cx); workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); assert!(workspace - .open_entry((tree.id(), Path::new("the-new-name").into()), cx) + .open_entry((tree.id(), Path::new("the-new-name.rs").into()), cx) .is_none()); }); let editor2 = workspace.update(&mut cx, |workspace, cx| {