Remove unnecessary Err
from get_canonicalized_path
(#8009)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
This commit is contained in:
parent
2767459f89
commit
22f4f313f1
7 changed files with 16 additions and 29 deletions
|
@ -85,7 +85,7 @@ pub fn get_normalized_path(path: &Path) -> PathBuf {
|
|||
///
|
||||
/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
|
||||
/// here if the path exists, just normalize it's components.
|
||||
pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
|
||||
pub fn get_canonicalized_path(path: &Path) -> PathBuf {
|
||||
let path = expand_tilde(path);
|
||||
let path = if path.is_relative() {
|
||||
helix_loader::current_working_dir().join(path)
|
||||
|
@ -93,7 +93,7 @@ pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
|
|||
path
|
||||
};
|
||||
|
||||
Ok(get_normalized_path(path.as_path()))
|
||||
get_normalized_path(path.as_path())
|
||||
}
|
||||
|
||||
pub fn get_relative_path(path: &Path) -> PathBuf {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,12 @@ pub enum PathOrId {
|
|||
}
|
||||
|
||||
impl PathOrId {
|
||||
fn get_canonicalized(self) -> std::io::Result<Self> {
|
||||
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<T: Item + 'static> Picker<T> {
|
|||
fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
|
||||
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
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
|
||||
fs::write(&paths[0], "1\n2\n3\n4")?;
|
||||
|
|
|
@ -708,7 +708,7 @@ impl Document {
|
|||
let mut doc = Self::from(rope, Some((encoding, has_bom)), config);
|
||||
|
||||
// set the path and try detecting the language
|
||||
doc.set_path(Some(path))?;
|
||||
doc.set_path(Some(path));
|
||||
if let Some(loader) = config_loader {
|
||||
doc.detect_language(loader);
|
||||
}
|
||||
|
@ -853,7 +853,7 @@ impl Document {
|
|||
let text = self.text().clone();
|
||||
|
||||
let path = match path {
|
||||
Some(path) => helix_core::path::get_canonicalized_path(&path)?,
|
||||
Some(path) => helix_core::path::get_canonicalized_path(&path),
|
||||
None => {
|
||||
if self.path.is_none() {
|
||||
bail!("Can't save with no path set!");
|
||||
|
@ -1047,18 +1047,14 @@ impl Document {
|
|||
self.encoding
|
||||
}
|
||||
|
||||
pub fn set_path(&mut self, path: Option<&Path>) -> Result<(), std::io::Error> {
|
||||
let path = path
|
||||
.map(helix_core::path::get_canonicalized_path)
|
||||
.transpose()?;
|
||||
pub fn set_path(&mut self, path: Option<&Path>) {
|
||||
let path = path.map(helix_core::path::get_canonicalized_path);
|
||||
|
||||
// if parent doesn't exist we still want to open the document
|
||||
// and error out when document is saved
|
||||
self.path = path;
|
||||
|
||||
self.detect_readonly();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the programming language for the file and load associated data (e.g. highlighting)
|
||||
|
|
|
@ -1436,7 +1436,7 @@ impl Editor {
|
|||
|
||||
// ??? possible use for integration tests
|
||||
pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, Error> {
|
||||
let path = helix_core::path::get_canonicalized_path(path)?;
|
||||
let path = helix_core::path::get_canonicalized_path(path);
|
||||
let id = self.document_by_path(&path).map(|doc| doc.id);
|
||||
|
||||
let id = if let Some(id) = id {
|
||||
|
|
Loading…
Reference in a new issue