aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-09-17 03:17:48 +0000
committerSkyler Hawthorne2022-10-19 02:31:39 +0000
commit3f07885b351748c5b8225aadb165f8ef7066f047 (patch)
tree37ece44a32184a6902fccdab77adaf13713917bc /helix-term/src
parentb530a86d1f15cc7df0e1ae8aa4bd02109ac33a8f (diff)
document should save even if formatter fails
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs15
-rw-r--r--helix-term/src/commands.rs27
-rw-r--r--helix-term/src/main.rs12
3 files changed, 31 insertions, 23 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index fe53d73d..4fde2a66 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -1,7 +1,6 @@
use arc_swap::{access::Map, ArcSwap};
use futures_util::Stream;
use helix_core::{
- config::{default_syntax_loader, user_syntax_loader},
diagnostic::{DiagnosticTag, NumberOrString},
path::get_relative_path,
pos_at_coords, syntax, Selection,
@@ -110,7 +109,11 @@ fn restore_term() -> Result<(), Error> {
}
impl Application {
- pub fn new(args: Args, config: Config) -> Result<Self, Error> {
+ pub fn new(
+ args: Args,
+ config: Config,
+ syn_loader_conf: syntax::Configuration,
+ ) -> Result<Self, Error> {
#[cfg(feature = "integration")]
setup_integration_logging();
@@ -137,14 +140,6 @@ impl Application {
})
.unwrap_or_else(|| theme_loader.default_theme(true_color));
- let syn_loader_conf = user_syntax_loader().unwrap_or_else(|err| {
- eprintln!("Bad language config: {}", err);
- eprintln!("Press <ENTER> to continue with default language config");
- use std::io::Read;
- // This waits for an enter press.
- let _ = std::io::stdin().read(&mut []);
- default_syntax_loader()
- });
let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));
let mut compositor = Compositor::new().context("build compositor")?;
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 6deecbe2..f6d583f5 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2518,7 +2518,8 @@ async fn make_format_callback(
format: impl Future<Output = Result<Transaction, FormatterError>> + Send + 'static,
write: Option<(Option<PathBuf>, bool)>,
) -> anyhow::Result<job::Callback> {
- let format = format.await?;
+ let format = format.await;
+
let call: job::Callback = Callback::Editor(Box::new(move |editor| {
if !editor.documents.contains_key(&doc_id) {
return;
@@ -2528,19 +2529,21 @@ async fn make_format_callback(
let doc = doc_mut!(editor, &doc_id);
let view = view_mut!(editor);
- if doc.version() == doc_version {
- apply_transaction(&format, doc, view);
- doc.append_changes_to_history(view.id);
- doc.detect_indent_and_line_ending();
- view.ensure_cursor_in_view(doc, scrolloff);
+ if let Ok(format) = format {
+ if doc.version() == doc_version {
+ apply_transaction(&format, doc, view);
+ doc.append_changes_to_history(view.id);
+ doc.detect_indent_and_line_ending();
+ view.ensure_cursor_in_view(doc, scrolloff);
+ } else {
+ log::info!("discarded formatting changes because the document changed");
+ }
+ }
- if let Some((path, force)) = write {
- if let Err(err) = doc.save(path, force) {
- editor.set_error(format!("Error saving: {}", err));
- }
+ if let Some((path, force)) = write {
+ if let Err(err) = doc.save(path, force) {
+ editor.set_error(format!("Error saving: {}", err));
}
- } else {
- log::info!("discarded formatting changes because the document changed");
}
}));
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index 726bf9e3..96b695c6 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -139,8 +139,18 @@ FLAGS:
Err(err) => return Err(Error::new(err)),
};
+ let syn_loader_conf = helix_core::config::user_syntax_loader().unwrap_or_else(|err| {
+ eprintln!("Bad language config: {}", err);
+ eprintln!("Press <ENTER> to continue with default language config");
+ use std::io::Read;
+ // This waits for an enter press.
+ let _ = std::io::stdin().read(&mut []);
+ helix_core::config::default_syntax_loader()
+ });
+
// TODO: use the thread local executor to spawn the application task separately from the work pool
- let mut app = Application::new(args, config).context("unable to create new application")?;
+ let mut app = Application::new(args, config, syn_loader_conf)
+ .context("unable to create new application")?;
let exit_code = app.run(&mut EventStream::new()).await?;