diff --git a/helix-lsp-types/src/lib.rs b/helix-lsp-types/src/lib.rs index 5024f6e7cbb3..c7b4f0f13285 100644 --- a/helix-lsp-types/src/lib.rs +++ b/helix-lsp-types/src/lib.rs @@ -42,9 +42,8 @@ const RESERVED: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS .add(b'='); impl Url { - #[allow(clippy::result_unit_err)] #[cfg(any(unix, target_os = "redox", target_os = "wasi"))] - pub fn from_file_path>(path: P) -> Result { + pub fn from_file_path>(path: P) -> Self { #[cfg(any(unix, target_os = "redox"))] use std::os::unix::prelude::OsStrExt; #[cfg(target_os = "wasi")] @@ -63,18 +62,16 @@ impl Url { // An URL's path must not be empty. serialization.push('/'); } - Ok(Self(serialization)) + Self(serialization) } - #[allow(clippy::result_unit_err)] #[cfg(windows)] - pub fn from_file_path>(path: P) -> Result { + pub fn from_file_path>(path: P) -> Self { from_file_path_windows(path.as_ref()) } - #[allow(clippy::result_unit_err)] #[cfg_attr(not(windows), allow(dead_code))] - fn from_file_path_windows(path: &Path) -> Result { + fn from_file_path_windows(path: &Path) -> Self { use std::path::{Component, Prefix}; fn is_windows_drive_letter(segment: &str) -> bool { @@ -123,16 +120,15 @@ impl Url { serialization.push('/'); } - Ok(Self(serialization)) + Self(serialization) } - #[allow(clippy::result_unit_err)] - pub fn from_directory_path>(path: P) -> Result { - let Self(mut serialization) = Self::from_file_path(path)?; + pub fn from_directory_path>(path: P) -> Self { + let Self(mut serialization) = Self::from_file_path(path); if !serialization.ends_with('/') { serialization.push('/'); } - Ok(Self(serialization)) + Self(serialization) } /// Returns the serialized representation of the URL as a `&str` diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index e8efa613f563..6fc4f38ead4e 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -42,8 +42,7 @@ fn workspace_for_path(path: &Path) -> WorkspaceFolder { lsp::WorkspaceFolder { name, - uri: lsp::Url::from_directory_path(path) - .expect("absolute paths can be converted to `Url`s"), + uri: lsp::Url::from_directory_path(path), } } @@ -203,9 +202,7 @@ impl Client { Transport::start(reader, writer, stderr, id, name.clone()); let workspace_folders = root.clone().into_iter().collect(); - let root_uri = root.clone().map(|root| { - lsp::Url::from_file_path(root).expect("absolute paths can be converted to `Url`s") - }); + let root_uri = root.clone().map(lsp::Url::from_file_path); // `root_uri` and `workspace_folder` can be empty in case there is no workspace // `root_url` can not, use `workspace` as a fallback let root_path = root.unwrap_or(workspace); @@ -743,11 +740,11 @@ impl Client { } else { Url::from_file_path(path) }; - Some(url.ok()?.into_string()) + url.into_string() }; let files = vec![lsp::FileRename { - old_uri: url_from_path(old_path)?, - new_uri: url_from_path(new_path)?, + old_uri: url_from_path(old_path), + new_uri: url_from_path(new_path), }]; let request = self.call_with_timeout::( &lsp::RenameFilesParams { files }, @@ -777,12 +774,12 @@ impl Client { } else { Url::from_file_path(path) }; - Some(url.ok()?.into_string()) + url.into_string() }; let files = vec![lsp::FileRename { - old_uri: url_from_path(old_path)?, - new_uri: url_from_path(new_path)?, + old_uri: url_from_path(old_path), + new_uri: url_from_path(new_path), }]; Some(self.notify::(lsp::RenameFilesParams { files })) } diff --git a/helix-lsp/src/file_event.rs b/helix-lsp/src/file_event.rs index c7297d67fc11..1d60f1370d4c 100644 --- a/helix-lsp/src/file_event.rs +++ b/helix-lsp/src/file_event.rs @@ -106,9 +106,7 @@ impl Handler { log::warn!("LSP client was dropped: {id}"); return false; }; - let Ok(uri) = lsp::Url::from_file_path(&path) else { - return true; - }; + let uri = lsp::Url::from_file_path(&path); log::debug!( "Sending didChangeWatchedFiles notification to client '{}'", client.name() diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 5a17c5b73f61..965190299c53 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1822,7 +1822,7 @@ impl Document { /// File path as a URL. pub fn url(&self) -> Option { - lsp::Url::from_file_path(self.path()?).ok() + self.path().map(lsp::Url::from_file_path) } pub fn uri(&self) -> Option {