From 22f4f313f1cbdaadafcc3dd471f5a0bb4f7034e1 Mon Sep 17 00:00:00 2001 From: nkitsaini Date: Mon, 21 Aug 2023 00:41:32 +0530 Subject: Remove unnecessary `Err` from `get_canonicalized_path` (#8009) Co-authored-by: Michael Davis --- helix-term/src/application.rs | 13 ++----------- helix-term/src/commands/typed.rs | 2 +- helix-term/src/ui/picker.rs | 10 +++++----- helix-term/tests/test/picker.rs | 2 +- 4 files changed, 9 insertions(+), 18 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index a97ae503..3e938917 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -160,7 +160,7 @@ impl Application { let path = helix_loader::runtime_file(Path::new("tutor")); editor.open(&path, Action::VerticalSplit)?; // Unset path to prevent accidentally saving to the original tutor file. - doc_mut!(editor).set_path(None)?; + doc_mut!(editor).set_path(None); } else if !args.files.is_empty() { let first = &args.files[0].0; // we know it's not empty if first.is_dir() { @@ -554,16 +554,7 @@ impl Application { let bytes = doc_save_event.text.len_bytes(); if doc.path() != Some(&doc_save_event.path) { - if let Err(err) = doc.set_path(Some(&doc_save_event.path)) { - log::error!( - "error setting path for doc '{:?}': {}", - doc.path(), - err.to_string(), - ); - - self.editor.set_error(err.to_string()); - return; - } + doc.set_path(Some(&doc_save_event.path)); let loader = self.editor.syn_loader.clone(); diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 4c7314b6..a7eb2244 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1679,7 +1679,7 @@ fn tutor( let path = helix_loader::runtime_file(Path::new("tutor")); cx.editor.open(&path, Action::Replace)?; // Unset path to prevent accidentally saving to the original tutor file. - doc_mut!(cx.editor).set_path(None)?; + doc_mut!(cx.editor).set_path(None); Ok(()) } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 5ee4c407..b134eb47 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -51,12 +51,12 @@ pub enum PathOrId { } impl PathOrId { - fn get_canonicalized(self) -> std::io::Result { + fn get_canonicalized(self) -> Self { use PathOrId::*; - Ok(match self { - Path(path) => Path(helix_core::path::get_canonicalized_path(&path)?), + match self { + Path(path) => Path(helix_core::path::get_canonicalized_path(&path)), Id(id) => Id(id), - }) + } } } @@ -375,7 +375,7 @@ impl Picker { fn current_file(&self, editor: &Editor) -> Option { self.selection() .and_then(|current| (self.file_fn.as_ref()?)(editor, current)) - .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line))) + .map(|(path_or_id, line)| (path_or_id.get_canonicalized(), line)) } /// Get (cached) preview for a given path. If a document corresponding diff --git a/helix-term/tests/test/picker.rs b/helix-term/tests/test/picker.rs index f6d1aa25..89e6531f 100644 --- a/helix-term/tests/test/picker.rs +++ b/helix-term/tests/test/picker.rs @@ -30,7 +30,7 @@ async fn test_picker_alt_ret() -> anyhow::Result<()> { ]; let paths = files .iter() - .map(|f| get_canonicalized_path(f.path()).unwrap()) + .map(|f| get_canonicalized_path(f.path())) .collect::>(); fs::write(&paths[0], "1\n2\n3\n4")?; -- cgit v1.2.3-70-g09d2