|
|
@ -205,6 +205,9 @@ fn write_impl(
|
|
|
|
if doc.path().is_none() {
|
|
|
|
if doc.path().is_none() {
|
|
|
|
bail!("cannot write a buffer without a filename");
|
|
|
|
bail!("cannot write a buffer without a filename");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "lsp")]
|
|
|
|
|
|
|
|
let future = {
|
|
|
|
let fmt = doc.auto_format().map(|fmt| {
|
|
|
|
let fmt = doc.auto_format().map(|fmt| {
|
|
|
|
let shared = fmt.shared();
|
|
|
|
let shared = fmt.shared();
|
|
|
|
let callback = make_format_callback(
|
|
|
|
let callback = make_format_callback(
|
|
|
@ -216,12 +219,17 @@ fn write_impl(
|
|
|
|
jobs.callback(callback);
|
|
|
|
jobs.callback(callback);
|
|
|
|
shared
|
|
|
|
shared
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let future = doc.format_and_save(fmt, force);
|
|
|
|
doc.format_and_save(fmt, force)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(feature = "lsp"))]
|
|
|
|
|
|
|
|
let future = doc.save(force);
|
|
|
|
|
|
|
|
|
|
|
|
cx.jobs.add(Job::new(future).wait_before_exiting());
|
|
|
|
cx.jobs.add(Job::new(future).wait_before_exiting());
|
|
|
|
|
|
|
|
|
|
|
|
if path.is_some() {
|
|
|
|
if path.is_some() {
|
|
|
|
let id = doc.id();
|
|
|
|
let id = doc.id();
|
|
|
|
doc.detect_language(cx.editor.syn_loader.clone());
|
|
|
|
doc.detect_language(cx.editor.syn_loader.clone());
|
|
|
|
|
|
|
|
#[cfg(feature = "lsp")]
|
|
|
|
let _ = cx.editor.refresh_language_server(id);
|
|
|
|
let _ = cx.editor.refresh_language_server(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
@ -259,6 +267,7 @@ fn format(
|
|
|
|
_event: PromptEvent,
|
|
|
|
_event: PromptEvent,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
let doc = doc!(cx.editor);
|
|
|
|
let doc = doc!(cx.editor);
|
|
|
|
|
|
|
|
#[cfg(feature = "lsp")]
|
|
|
|
if let Some(format) = doc.format() {
|
|
|
|
if let Some(format) = doc.format() {
|
|
|
|
let callback =
|
|
|
|
let callback =
|
|
|
|
make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
|
|
|
|
make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
|
|
|
@ -466,6 +475,8 @@ fn write_all_impl(
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "lsp")]
|
|
|
|
|
|
|
|
let future = {
|
|
|
|
let fmt = doc.auto_format().map(|fmt| {
|
|
|
|
let fmt = doc.auto_format().map(|fmt| {
|
|
|
|
let shared = fmt.shared();
|
|
|
|
let shared = fmt.shared();
|
|
|
|
let callback = make_format_callback(
|
|
|
|
let callback = make_format_callback(
|
|
|
@ -477,7 +488,11 @@ fn write_all_impl(
|
|
|
|
jobs.callback(callback);
|
|
|
|
jobs.callback(callback);
|
|
|
|
shared
|
|
|
|
shared
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let future = doc.format_and_save(fmt, force);
|
|
|
|
doc.format_and_save(fmt, force)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(feature = "lsp"))]
|
|
|
|
|
|
|
|
let future = doc.save(force);
|
|
|
|
|
|
|
|
|
|
|
|
jobs.add(Job::new(future).wait_before_exiting());
|
|
|
|
jobs.add(Job::new(future).wait_before_exiting());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1000,6 +1015,7 @@ fn language(
|
|
|
|
doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone());
|
|
|
|
doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone());
|
|
|
|
|
|
|
|
|
|
|
|
let id = doc.id();
|
|
|
|
let id = doc.id();
|
|
|
|
|
|
|
|
#[cfg(feature = "lsp")]
|
|
|
|
cx.editor.refresh_language_server(id);
|
|
|
|
cx.editor.refresh_language_server(id);
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|