|
|
@ -1917,31 +1917,28 @@ fn append_to_line(cx: &mut Context) {
|
|
|
|
|
|
|
|
|
|
|
|
// Creates an LspCallback that waits for formatting changes to be computed. When they're done,
|
|
|
|
// Creates an LspCallback that waits for formatting changes to be computed. When they're done,
|
|
|
|
// it applies them, but only if the doc hasn't changed.
|
|
|
|
// it applies them, but only if the doc hasn't changed.
|
|
|
|
fn make_format_callback(
|
|
|
|
async fn make_format_callback(
|
|
|
|
doc_id: DocumentId,
|
|
|
|
doc_id: DocumentId,
|
|
|
|
doc_version: i32,
|
|
|
|
doc_version: i32,
|
|
|
|
set_unmodified: bool,
|
|
|
|
set_unmodified: bool,
|
|
|
|
format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
|
|
|
|
format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
|
|
|
|
) -> impl Future<Output = anyhow::Result<job::Callback>> {
|
|
|
|
) -> anyhow::Result<job::Callback> {
|
|
|
|
async move {
|
|
|
|
let format = format.await;
|
|
|
|
let format = format.await;
|
|
|
|
let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
|
|
|
|
let call: job::Callback =
|
|
|
|
let view_id = view!(editor).id;
|
|
|
|
Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
|
|
|
|
if let Some(doc) = editor.document_mut(doc_id) {
|
|
|
|
let view_id = view!(editor).id;
|
|
|
|
if doc.version() == doc_version {
|
|
|
|
if let Some(doc) = editor.document_mut(doc_id) {
|
|
|
|
doc.apply(&Transaction::from(format), view_id);
|
|
|
|
if doc.version() == doc_version {
|
|
|
|
doc.append_changes_to_history(view_id);
|
|
|
|
doc.apply(&Transaction::from(format), view_id);
|
|
|
|
if set_unmodified {
|
|
|
|
doc.append_changes_to_history(view_id);
|
|
|
|
doc.reset_modified();
|
|
|
|
if set_unmodified {
|
|
|
|
|
|
|
|
doc.reset_modified();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log::info!("discarded formatting changes because the document changed");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Ok(call)
|
|
|
|
log::info!("discarded formatting changes because the document changed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(call)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum Open {
|
|
|
|
enum Open {
|
|
|
|