Skip to content

Commit

Permalink
flush writes on force quit (#4397)
Browse files Browse the repository at this point in the history
When force quitting, we need to block on the pending writes to ensure
that write commands succeed before exiting, and also to avoid a crash
when all the views are gone before the auto format call returns from
the LS.
  • Loading branch information
dead10ck authored Oct 21, 2022
1 parent 74a6a22 commit f486f34
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 43 deletions.
1 change: 1 addition & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn force_quit(

ensure!(args.is_empty(), ":quit! takes no arguments");

cx.block_try_flush_writes()?;
cx.editor.close(view!(cx.editor).id);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod test {

use self::helpers::*;

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn hello_world() -> anyhow::Result<()> {
test(("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#")).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/auto_indent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn auto_indent_c() -> anyhow::Result<()> {
test_with_config(
Args {
Expand Down
50 changes: 25 additions & 25 deletions helix-term/tests/test/auto_pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn matching_pairs() -> impl Iterator<Item = &'static (char, char)> {
DEFAULT_PAIRS.iter().filter(|(open, close)| open == close)
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_basic() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -26,7 +26,7 @@ async fn insert_basic() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
// NOTE: these are multi-byte Unicode characters
let pairs = hashmap!('„' => '“', '‚' => '‘', '「' => '」');
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_after_word() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -91,7 +91,7 @@ async fn insert_after_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_before_word() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -105,7 +105,7 @@ async fn insert_before_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_before_word_selection() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -119,7 +119,7 @@ async fn insert_before_word_selection() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_before_word_selection_trailing_word() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -133,7 +133,7 @@ async fn insert_before_word_selection_trailing_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_closer_selection_trailing_word() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -147,7 +147,7 @@ async fn insert_closer_selection_trailing_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_before_eol() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -166,7 +166,7 @@ async fn insert_before_eol() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test_with_config(
Expand All @@ -191,7 +191,7 @@ async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_multi_range() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -210,7 +210,7 @@ async fn insert_multi_range() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_before_multi_code_point_graphemes() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -223,7 +223,7 @@ async fn insert_before_multi_code_point_graphemes() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_at_end_of_document() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test(TestCase {
Expand All @@ -248,7 +248,7 @@ async fn insert_at_end_of_document() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_close_inside_pair() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -272,7 +272,7 @@ async fn insert_close_inside_pair() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_close_inside_pair_multi() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -296,7 +296,7 @@ async fn insert_close_inside_pair_multi() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_nested_open_inside_pair() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -320,7 +320,7 @@ async fn insert_nested_open_inside_pair() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_nested_open_inside_pair_multi() -> anyhow::Result<()> {
for outer_pair in DEFAULT_PAIRS {
for inner_pair in DEFAULT_PAIRS {
Expand Down Expand Up @@ -352,7 +352,7 @@ async fn insert_nested_open_inside_pair_multi() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_basic() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -371,7 +371,7 @@ async fn append_basic() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_multi_range() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -390,7 +390,7 @@ async fn append_multi_range() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_close_inside_pair() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -414,7 +414,7 @@ async fn append_close_inside_pair() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_close_inside_pair_multi() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS {
test((
Expand All @@ -438,7 +438,7 @@ async fn append_close_inside_pair_multi() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_end_of_word() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -457,7 +457,7 @@ async fn append_end_of_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_middle_of_word() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -471,7 +471,7 @@ async fn append_middle_of_word() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_end_of_word_multi() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -490,7 +490,7 @@ async fn append_end_of_word_multi() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_inside_nested_pair() -> anyhow::Result<()> {
for pair in differing_pairs() {
test((
Expand All @@ -514,7 +514,7 @@ async fn append_inside_nested_pair() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn append_inside_nested_pair_multi() -> anyhow::Result<()> {
for outer_pair in DEFAULT_PAIRS {
for inner_pair in DEFAULT_PAIRS {
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_selection_duplication() -> anyhow::Result<()> {
// Forward
test((
Expand Down
14 changes: 7 additions & 7 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_mode_cursor_position() -> anyhow::Result<()> {
test(TestCase {
in_text: String::new(),
Expand All @@ -19,7 +19,7 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> {
}

/// Range direction is preserved when escaping insert mode to normal
#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
test(("#[f|]#oo\n", "vll<A-;><esc>", "#[|foo]#\n")).await?;
test((
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {

/// Ensure the very initial cursor in an opened file is the width of
/// the first grapheme
#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
let file = helpers::temp_file_with_contents(content)?;
Expand All @@ -88,7 +88,7 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn cursor_position_append_eof() -> anyhow::Result<()> {
// Selection is fowards
test((
Expand All @@ -109,7 +109,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
test_with_config(
Args {
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
test_with_config(
Args {
Expand Down Expand Up @@ -173,7 +173,7 @@ async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Res
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
// Note: the anchor stays put and the head moves back.
test_with_config(
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_history_completion() -> anyhow::Result<()> {
test_key_sequence(
&mut AppBuilder::new().build()?,
Expand Down
14 changes: 7 additions & 7 deletions helix-term/tests/test/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use helix_view::doc;

use super::*;

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write() -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?;
let mut app = helpers::AppBuilder::new()
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?;
let mut app = helpers::AppBuilder::new()
Expand Down Expand Up @@ -133,7 +133,7 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?;

Expand All @@ -158,7 +158,7 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
helpers::test_key_sequence_with_input_text(
None,
Expand All @@ -179,7 +179,7 @@ async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_auto_format_fails_still_writes() -> anyhow::Result<()> {
let mut file = tempfile::Builder::new().suffix(".rs").tempfile()?;

Expand All @@ -203,7 +203,7 @@ async fn test_write_auto_format_fails_still_writes() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_new_path() -> anyhow::Result<()> {
let mut file1 = tempfile::NamedTempFile::new().unwrap();
let mut file2 = tempfile::NamedTempFile::new().unwrap();
Expand Down Expand Up @@ -249,7 +249,7 @@ async fn test_write_new_path() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_write_fail_new_path() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?;

Expand Down

0 comments on commit f486f34

Please sign in to comment.