on master help sign in
Make set_unmodified an enum.
commitb39e452d7714a74419e02195183a659ae4efb1f6 authorJoe Neeman <joeneeman@gmail.com> dateTue 29 Jun 2021, 22:52 (5 years ago) parent2902a10
1 file changed+17−4
helix-term/src/commands.rs+17−4
helix-term/src/commands.rs+17−4
@@ -1162,7 +1162,12 @@ mod cmd {
11621162 }
11631163 let fmt = doc.auto_format().map(|fmt| {
11641164 let shared = fmt.shared();
1165− let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone());
1165+ let callback = make_format_callback(
1166+ doc.id(),
1167+ doc.version(),
1168+ Modified::SetUnmodified,
1169+ shared.clone(),
1170+ );
11661171 jobs.callback(callback);
11671172 shared
11681173 });
@@ -1187,7 +1192,8 @@ mod cmd {
11871192 let (_, doc) = current!(cx.editor);
11881193
11891194 if let Some(format) = doc.format() {
1190− let callback = make_format_callback(doc.id(), doc.version(), false, format);
1195+ let callback =
1196+ make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
11911197 cx.jobs.callback(callback);
11921198 }
11931199 }
@@ -1907,6 +1913,13 @@ fn append_to_line(cx: &mut Context) {
19071913 doc.set_selection(view.id, selection);
19081914}
19091915
1916+/// Sometimes when applying formatting changes we want to mark the buffer as unmodified, for
1917+/// example because we just applied the same changes while saving.
1918+enum Modified {
1919+ SetUnmodified,
1920+ LeaveModified,
1921+}
1922+
19101923// Creates an LspCallback that waits for formatting changes to be computed. When they're done,
19111924// it applies them, but only if the doc hasn't changed.
19121925//
@@ -1915,7 +1928,7 @@ fn append_to_line(cx: &mut Context) {
19151928async fn make_format_callback(
19161929 doc_id: DocumentId,
19171930 doc_version: i32,
1918− set_unmodified: bool,
1931+ modified: Modified,
19191932 format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
19201933) -> anyhow::Result<job::Callback> {
19211934 let format = format.await;
@@ -1925,7 +1938,7 @@ async fn make_format_callback(
19251938 if doc.version() == doc_version {
19261939 doc.apply(&Transaction::from(format), view_id);
19271940 doc.append_changes_to_history(view_id);
1928− if set_unmodified {
1941+ if let Modified::SetUnmodified = modified {
19291942 doc.reset_modified();
19301943 }
19311944 } else {