on master help sign in
Remove unnecessary `Err` from `get_canonicalized_path` (#8009)
22f4f31nkitsaini
helix-core/src/path.rs+2−2
@@ -85,7 +85,7 @@ pub fn get_normalized_path(path: &Path) -> PathBuf {
85///
85///
86/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
86/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
87/// here if the path exists, just normalize it's components.
87/// here if the path exists, just normalize it's components.
88−pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
88+pub fn get_canonicalized_path(path: &Path) -> PathBuf {
89 let path = expand_tilde(path);
89 let path = expand_tilde(path);
90 let path = if path.is_relative() {
90 let path = if path.is_relative() {
91 helix_loader::current_working_dir().join(path)
91 helix_loader::current_working_dir().join(path)
@@ -93,7 +93,7 @@ pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
93 path
93 path
94 };
94 };
95
95
96− Ok(get_normalized_path(path.as_path()))
96+ get_normalized_path(path.as_path())
97}
97}
98
98
99pub fn get_relative_path(path: &Path) -> PathBuf {
99pub fn get_relative_path(path: &Path) -> PathBuf {
helix-term/src/application.rs+2−11
@@ -160,7 +160,7 @@ impl Application {
160 let path = helix_loader::runtime_file(Path::new("tutor"));
160 let path = helix_loader::runtime_file(Path::new("tutor"));
161 editor.open(&path, Action::VerticalSplit)?;
161 editor.open(&path, Action::VerticalSplit)?;
162 // Unset path to prevent accidentally saving to the original tutor file.
162 // Unset path to prevent accidentally saving to the original tutor file.
163− doc_mut!(editor).set_path(None)?;
163+ doc_mut!(editor).set_path(None);
164 } else if !args.files.is_empty() {
164 } else if !args.files.is_empty() {
165 let first = &args.files[0].0; // we know it's not empty
165 let first = &args.files[0].0; // we know it's not empty
166 if first.is_dir() {
166 if first.is_dir() {
@@ -554,16 +554,7 @@ impl Application {
554 let bytes = doc_save_event.text.len_bytes();
554 let bytes = doc_save_event.text.len_bytes();
555
555
556 if doc.path() != Some(&doc_save_event.path) {
556 if doc.path() != Some(&doc_save_event.path) {
557− if let Err(err) = doc.set_path(Some(&doc_save_event.path)) {
557+ doc.set_path(Some(&doc_save_event.path));
558− log::error!(
559− "error setting path for doc '{:?}': {}",
560− doc.path(),
561− err.to_string(),
562− );
563−
564− self.editor.set_error(err.to_string());
565− return;
566− }
567
558
568 let loader = self.editor.syn_loader.clone();
559 let loader = self.editor.syn_loader.clone();
569
560
helix-term/src/commands/typed.rs+1−1
@@ -1679,7 +1679,7 @@ fn tutor(
1679 let path = helix_loader::runtime_file(Path::new("tutor"));
1679 let path = helix_loader::runtime_file(Path::new("tutor"));
1680 cx.editor.open(&path, Action::Replace)?;
1680 cx.editor.open(&path, Action::Replace)?;
1681 // Unset path to prevent accidentally saving to the original tutor file.
1681 // Unset path to prevent accidentally saving to the original tutor file.
1682− doc_mut!(cx.editor).set_path(None)?;
1682+ doc_mut!(cx.editor).set_path(None);
1683 Ok(())
1683 Ok(())
1684}
1684}
1685
1685
helix-term/src/ui/picker.rs+5−5
@@ -51,12 +51,12 @@ pub enum PathOrId {
51}
51}
52
52
53impl PathOrId {
53impl PathOrId {
54− fn get_canonicalized(self) -> std::io::Result<Self> {
54+ fn get_canonicalized(self) -> Self {
55 use PathOrId::*;
55 use PathOrId::*;
56− Ok(match self {
56+ match self {
57− Path(path) => Path(helix_core::path::get_canonicalized_path(&path)?),
57+ Path(path) => Path(helix_core::path::get_canonicalized_path(&path)),
58 Id(id) => Id(id),
58 Id(id) => Id(id),
59− })
59+ }
60 }
60 }
61}
61}
62
62
@@ -375,7 +375,7 @@ impl<T: Item + 'static> Picker<T> {
375 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
375 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
376 self.selection()
376 self.selection()
377 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
377 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
378− .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
378+ .map(|(path_or_id, line)| (path_or_id.get_canonicalized(), line))
379 }
379 }
380
380
381 /// Get (cached) preview for a given path. If a document corresponding
381 /// Get (cached) preview for a given path. If a document corresponding
helix-term/tests/test/picker.rs+1−1
@@ -30,7 +30,7 @@ async fn test_picker_alt_ret() -> anyhow::Result<()> {
30 ];
30 ];
31 let paths = files
31 let paths = files
32 .iter()
32 .iter()
33− .map(|f| get_canonicalized_path(f.path()).unwrap())
33+ .map(|f| get_canonicalized_path(f.path()))
34 .collect::<Vec<_>>();
34 .collect::<Vec<_>>();
35
35
36 fs::write(&paths[0], "1\n2\n3\n4")?;
36 fs::write(&paths[0], "1\n2\n3\n4")?;
helix-view/src/document.rs+4−8
@@ -708,7 +708,7 @@ impl Document {
708 let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
708 let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
709
709
710 // set the path and try detecting the language
710 // set the path and try detecting the language
711− doc.set_path(Some(path))?;
711+ doc.set_path(Some(path));
712 if let Some(loader) = config_loader {
712 if let Some(loader) = config_loader {
713 doc.detect_language(loader);
713 doc.detect_language(loader);
714 }
714 }
@@ -853,7 +853,7 @@ impl Document {
853 let text = self.text().clone();
853 let text = self.text().clone();
854
854
855 let path = match path {
855 let path = match path {
856− Some(path) => helix_core::path::get_canonicalized_path(&path)?,
856+ Some(path) => helix_core::path::get_canonicalized_path(&path),
857 None => {
857 None => {
858 if self.path.is_none() {
858 if self.path.is_none() {
859 bail!("Can't save with no path set!");
859 bail!("Can't save with no path set!");
@@ -1047,18 +1047,14 @@ impl Document {
1047 self.encoding
1047 self.encoding
1048 }
1048 }
1049
1049
1050− pub fn set_path(&mut self, path: Option<&Path>) -> Result<(), std::io::Error> {
1050+ pub fn set_path(&mut self, path: Option<&Path>) {
1051− let path = path
1052− .map(helix_core::path::get_canonicalized_path)
1051+ let path = path.map(helix_core::path::get_canonicalized_path);
1053− .transpose()?;
1054
1052
1055 // if parent doesn't exist we still want to open the document
1053 // if parent doesn't exist we still want to open the document
1056 // and error out when document is saved
1054 // and error out when document is saved
1057 self.path = path;
1055 self.path = path;
1058
1056
1059 self.detect_readonly();
1057 self.detect_readonly();
1060−
1061− Ok(())
1062 }
1058 }
1063
1059
1064 /// Set the programming language for the file and load associated data (e.g. highlighting)
1060 /// Set the programming language for the file and load associated data (e.g. highlighting)
helix-view/src/editor.rs+1−1
@@ -1436,7 +1436,7 @@ impl Editor {
1436
1436
1437 // ??? possible use for integration tests
1437 // ??? possible use for integration tests
1438 pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, Error> {
1438 pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, Error> {
1439− let path = helix_core::path::get_canonicalized_path(path)?;
1439+ let path = helix_core::path::get_canonicalized_path(path);
1440 let id = self.document_by_path(&path).map(|doc| doc.id);
1440 let id = self.document_by_path(&path).map(|doc| doc.id);
1441
1441
1442 let id = if let Some(id) = id {
1442 let id = if let Some(id) = id {