Skip to content

Commit f486f34

Browse files
authored
flush writes on force quit (#4397)
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.
1 parent 74a6a22 commit f486f34

File tree

8 files changed

+44
-43
lines changed

8 files changed

+44
-43
lines changed

helix-term/src/commands/typed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn force_quit(
5151

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

54+
cx.block_try_flush_writes()?;
5455
cx.editor.close(view!(cx.editor).id);
5556

5657
Ok(())

helix-term/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod test {
1111

1212
use self::helpers::*;
1313

14-
#[tokio::test]
14+
#[tokio::test(flavor = "multi_thread")]
1515
async fn hello_world() -> anyhow::Result<()> {
1616
test(("#[\n|]#", "ihello world<esc>", "hello world#[|\n]#")).await?;
1717
Ok(())

helix-term/tests/test/auto_indent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
#[tokio::test]
3+
#[tokio::test(flavor = "multi_thread")]
44
async fn auto_indent_c() -> anyhow::Result<()> {
55
test_with_config(
66
Args {

helix-term/tests/test/auto_pairs.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn matching_pairs() -> impl Iterator<Item = &'static (char, char)> {
1212
DEFAULT_PAIRS.iter().filter(|(open, close)| open == close)
1313
}
1414

15-
#[tokio::test]
15+
#[tokio::test(flavor = "multi_thread")]
1616
async fn insert_basic() -> anyhow::Result<()> {
1717
for pair in DEFAULT_PAIRS {
1818
test((
@@ -26,7 +26,7 @@ async fn insert_basic() -> anyhow::Result<()> {
2626
Ok(())
2727
}
2828

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

71-
#[tokio::test]
71+
#[tokio::test(flavor = "multi_thread")]
7272
async fn insert_after_word() -> anyhow::Result<()> {
7373
for pair in differing_pairs() {
7474
test((
@@ -91,7 +91,7 @@ async fn insert_after_word() -> anyhow::Result<()> {
9191
Ok(())
9292
}
9393

94-
#[tokio::test]
94+
#[tokio::test(flavor = "multi_thread")]
9595
async fn insert_before_word() -> anyhow::Result<()> {
9696
for pair in DEFAULT_PAIRS {
9797
test((
@@ -105,7 +105,7 @@ async fn insert_before_word() -> anyhow::Result<()> {
105105
Ok(())
106106
}
107107

108-
#[tokio::test]
108+
#[tokio::test(flavor = "multi_thread")]
109109
async fn insert_before_word_selection() -> anyhow::Result<()> {
110110
for pair in DEFAULT_PAIRS {
111111
test((
@@ -119,7 +119,7 @@ async fn insert_before_word_selection() -> anyhow::Result<()> {
119119
Ok(())
120120
}
121121

122-
#[tokio::test]
122+
#[tokio::test(flavor = "multi_thread")]
123123
async fn insert_before_word_selection_trailing_word() -> anyhow::Result<()> {
124124
for pair in differing_pairs() {
125125
test((
@@ -133,7 +133,7 @@ async fn insert_before_word_selection_trailing_word() -> anyhow::Result<()> {
133133
Ok(())
134134
}
135135

136-
#[tokio::test]
136+
#[tokio::test(flavor = "multi_thread")]
137137
async fn insert_closer_selection_trailing_word() -> anyhow::Result<()> {
138138
for pair in differing_pairs() {
139139
test((
@@ -147,7 +147,7 @@ async fn insert_closer_selection_trailing_word() -> anyhow::Result<()> {
147147
Ok(())
148148
}
149149

150-
#[tokio::test]
150+
#[tokio::test(flavor = "multi_thread")]
151151
async fn insert_before_eol() -> anyhow::Result<()> {
152152
for pair in DEFAULT_PAIRS {
153153
test((
@@ -166,7 +166,7 @@ async fn insert_before_eol() -> anyhow::Result<()> {
166166
Ok(())
167167
}
168168

169-
#[tokio::test]
169+
#[tokio::test(flavor = "multi_thread")]
170170
async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
171171
for pair in DEFAULT_PAIRS {
172172
test_with_config(
@@ -191,7 +191,7 @@ async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
191191
Ok(())
192192
}
193193

194-
#[tokio::test]
194+
#[tokio::test(flavor = "multi_thread")]
195195
async fn insert_multi_range() -> anyhow::Result<()> {
196196
for pair in DEFAULT_PAIRS {
197197
test((
@@ -210,7 +210,7 @@ async fn insert_multi_range() -> anyhow::Result<()> {
210210
Ok(())
211211
}
212212

213-
#[tokio::test]
213+
#[tokio::test(flavor = "multi_thread")]
214214
async fn insert_before_multi_code_point_graphemes() -> anyhow::Result<()> {
215215
for pair in differing_pairs() {
216216
test((
@@ -223,7 +223,7 @@ async fn insert_before_multi_code_point_graphemes() -> anyhow::Result<()> {
223223
Ok(())
224224
}
225225

226-
#[tokio::test]
226+
#[tokio::test(flavor = "multi_thread")]
227227
async fn insert_at_end_of_document() -> anyhow::Result<()> {
228228
for pair in DEFAULT_PAIRS {
229229
test(TestCase {
@@ -248,7 +248,7 @@ async fn insert_at_end_of_document() -> anyhow::Result<()> {
248248
Ok(())
249249
}
250250

251-
#[tokio::test]
251+
#[tokio::test(flavor = "multi_thread")]
252252
async fn insert_close_inside_pair() -> anyhow::Result<()> {
253253
for pair in DEFAULT_PAIRS {
254254
test((
@@ -272,7 +272,7 @@ async fn insert_close_inside_pair() -> anyhow::Result<()> {
272272
Ok(())
273273
}
274274

275-
#[tokio::test]
275+
#[tokio::test(flavor = "multi_thread")]
276276
async fn insert_close_inside_pair_multi() -> anyhow::Result<()> {
277277
for pair in DEFAULT_PAIRS {
278278
test((
@@ -296,7 +296,7 @@ async fn insert_close_inside_pair_multi() -> anyhow::Result<()> {
296296
Ok(())
297297
}
298298

299-
#[tokio::test]
299+
#[tokio::test(flavor = "multi_thread")]
300300
async fn insert_nested_open_inside_pair() -> anyhow::Result<()> {
301301
for pair in differing_pairs() {
302302
test((
@@ -320,7 +320,7 @@ async fn insert_nested_open_inside_pair() -> anyhow::Result<()> {
320320
Ok(())
321321
}
322322

323-
#[tokio::test]
323+
#[tokio::test(flavor = "multi_thread")]
324324
async fn insert_nested_open_inside_pair_multi() -> anyhow::Result<()> {
325325
for outer_pair in DEFAULT_PAIRS {
326326
for inner_pair in DEFAULT_PAIRS {
@@ -352,7 +352,7 @@ async fn insert_nested_open_inside_pair_multi() -> anyhow::Result<()> {
352352
Ok(())
353353
}
354354

355-
#[tokio::test]
355+
#[tokio::test(flavor = "multi_thread")]
356356
async fn append_basic() -> anyhow::Result<()> {
357357
for pair in DEFAULT_PAIRS {
358358
test((
@@ -371,7 +371,7 @@ async fn append_basic() -> anyhow::Result<()> {
371371
Ok(())
372372
}
373373

374-
#[tokio::test]
374+
#[tokio::test(flavor = "multi_thread")]
375375
async fn append_multi_range() -> anyhow::Result<()> {
376376
for pair in DEFAULT_PAIRS {
377377
test((
@@ -390,7 +390,7 @@ async fn append_multi_range() -> anyhow::Result<()> {
390390
Ok(())
391391
}
392392

393-
#[tokio::test]
393+
#[tokio::test(flavor = "multi_thread")]
394394
async fn append_close_inside_pair() -> anyhow::Result<()> {
395395
for pair in DEFAULT_PAIRS {
396396
test((
@@ -414,7 +414,7 @@ async fn append_close_inside_pair() -> anyhow::Result<()> {
414414
Ok(())
415415
}
416416

417-
#[tokio::test]
417+
#[tokio::test(flavor = "multi_thread")]
418418
async fn append_close_inside_pair_multi() -> anyhow::Result<()> {
419419
for pair in DEFAULT_PAIRS {
420420
test((
@@ -438,7 +438,7 @@ async fn append_close_inside_pair_multi() -> anyhow::Result<()> {
438438
Ok(())
439439
}
440440

441-
#[tokio::test]
441+
#[tokio::test(flavor = "multi_thread")]
442442
async fn append_end_of_word() -> anyhow::Result<()> {
443443
for pair in differing_pairs() {
444444
test((
@@ -457,7 +457,7 @@ async fn append_end_of_word() -> anyhow::Result<()> {
457457
Ok(())
458458
}
459459

460-
#[tokio::test]
460+
#[tokio::test(flavor = "multi_thread")]
461461
async fn append_middle_of_word() -> anyhow::Result<()> {
462462
for pair in differing_pairs() {
463463
test((
@@ -471,7 +471,7 @@ async fn append_middle_of_word() -> anyhow::Result<()> {
471471
Ok(())
472472
}
473473

474-
#[tokio::test]
474+
#[tokio::test(flavor = "multi_thread")]
475475
async fn append_end_of_word_multi() -> anyhow::Result<()> {
476476
for pair in differing_pairs() {
477477
test((
@@ -490,7 +490,7 @@ async fn append_end_of_word_multi() -> anyhow::Result<()> {
490490
Ok(())
491491
}
492492

493-
#[tokio::test]
493+
#[tokio::test(flavor = "multi_thread")]
494494
async fn append_inside_nested_pair() -> anyhow::Result<()> {
495495
for pair in differing_pairs() {
496496
test((
@@ -514,7 +514,7 @@ async fn append_inside_nested_pair() -> anyhow::Result<()> {
514514
Ok(())
515515
}
516516

517-
#[tokio::test]
517+
#[tokio::test(flavor = "multi_thread")]
518518
async fn append_inside_nested_pair_multi() -> anyhow::Result<()> {
519519
for outer_pair in DEFAULT_PAIRS {
520520
for inner_pair in DEFAULT_PAIRS {

helix-term/tests/test/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
9494
Ok(())
9595
}
9696

97-
#[tokio::test]
97+
#[tokio::test(flavor = "multi_thread")]
9898
async fn test_selection_duplication() -> anyhow::Result<()> {
9999
// Forward
100100
test((

helix-term/tests/test/movement.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
#[tokio::test]
3+
#[tokio::test(flavor = "multi_thread")]
44
async fn insert_mode_cursor_position() -> anyhow::Result<()> {
55
test(TestCase {
66
in_text: String::new(),
@@ -19,7 +19,7 @@ async fn insert_mode_cursor_position() -> anyhow::Result<()> {
1919
}
2020

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

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

91-
#[tokio::test]
91+
#[tokio::test(flavor = "multi_thread")]
9292
async fn cursor_position_append_eof() -> anyhow::Result<()> {
9393
// Selection is fowards
9494
test((
@@ -109,7 +109,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> {
109109
Ok(())
110110
}
111111

112-
#[tokio::test]
112+
#[tokio::test(flavor = "multi_thread")]
113113
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
114114
test_with_config(
115115
Args {
@@ -141,7 +141,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::
141141
Ok(())
142142
}
143143

144-
#[tokio::test]
144+
#[tokio::test(flavor = "multi_thread")]
145145
async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
146146
test_with_config(
147147
Args {
@@ -173,7 +173,7 @@ async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Res
173173
Ok(())
174174
}
175175

176-
#[tokio::test]
176+
#[tokio::test(flavor = "multi_thread")]
177177
async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
178178
// Note: the anchor stays put and the head moves back.
179179
test_with_config(

helix-term/tests/test/prompt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
#[tokio::test]
3+
#[tokio::test(flavor = "multi_thread")]
44
async fn test_history_completion() -> anyhow::Result<()> {
55
test_key_sequence(
66
&mut AppBuilder::new().build()?,

helix-term/tests/test/write.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use helix_view::doc;
88

99
use super::*;
1010

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

95-
#[tokio::test]
95+
#[tokio::test(flavor = "multi_thread")]
9696
async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
9797
let file = helpers::new_readonly_tempfile()?;
9898
let mut app = helpers::AppBuilder::new()
@@ -133,7 +133,7 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
133133
Ok(())
134134
}
135135

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

@@ -158,7 +158,7 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
158158
Ok(())
159159
}
160160

161-
#[tokio::test]
161+
#[tokio::test(flavor = "multi_thread")]
162162
async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
163163
helpers::test_key_sequence_with_input_text(
164164
None,
@@ -179,7 +179,7 @@ async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
179179
Ok(())
180180
}
181181

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

@@ -203,7 +203,7 @@ async fn test_write_auto_format_fails_still_writes() -> anyhow::Result<()> {
203203
Ok(())
204204
}
205205

206-
#[tokio::test]
206+
#[tokio::test(flavor = "multi_thread")]
207207
async fn test_write_new_path() -> anyhow::Result<()> {
208208
let mut file1 = tempfile::NamedTempFile::new().unwrap();
209209
let mut file2 = tempfile::NamedTempFile::new().unwrap();
@@ -249,7 +249,7 @@ async fn test_write_new_path() -> anyhow::Result<()> {
249249
Ok(())
250250
}
251251

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

0 commit comments

Comments
 (0)