|
|
@ -1160,20 +1160,12 @@ mod cmd {
|
|
|
|
if doc.path().is_none() {
|
|
|
|
if doc.path().is_none() {
|
|
|
|
return Err(anyhow!("cannot write a buffer without a filename"));
|
|
|
|
return Err(anyhow!("cannot write a buffer without a filename"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let autofmt = doc
|
|
|
|
let fmt = doc.auto_format().map(|fmt| {
|
|
|
|
.language_config()
|
|
|
|
let shared = fmt.shared();
|
|
|
|
.map(|config| config.auto_format)
|
|
|
|
let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone());
|
|
|
|
.unwrap_or_default();
|
|
|
|
jobs.callback(callback);
|
|
|
|
let fmt = if autofmt {
|
|
|
|
shared
|
|
|
|
doc.format().map(|fmt| {
|
|
|
|
});
|
|
|
|
let shared = fmt.shared();
|
|
|
|
|
|
|
|
let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone());
|
|
|
|
|
|
|
|
jobs.callback(callback);
|
|
|
|
|
|
|
|
shared
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(tokio::spawn(doc.format_and_save(fmt)))
|
|
|
|
Ok(tokio::spawn(doc.format_and_save(fmt)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1917,6 +1909,9 @@ 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.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// TODO: provide some way to cancel this, probably as part of a more general job cancellation
|
|
|
|
|
|
|
|
// scheme
|
|
|
|
async fn make_format_callback(
|
|
|
|
async fn make_format_callback(
|
|
|
|
doc_id: DocumentId,
|
|
|
|
doc_id: DocumentId,
|
|
|
|
doc_version: i32,
|
|
|
|
doc_version: i32,
|
|
|
|