mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-18 21:17:08 +04:00
Remove unused Result wrapper for Path->Url conversion
This commit is contained in:
parent
a36806e326
commit
61491af15e
@ -42,9 +42,8 @@
|
|||||||
.add(b'=');
|
.add(b'=');
|
||||||
|
|
||||||
impl Url {
|
impl Url {
|
||||||
#[allow(clippy::result_unit_err)]
|
|
||||||
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
|
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
|
||||||
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self, ()> {
|
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Self {
|
||||||
#[cfg(any(unix, target_os = "redox"))]
|
#[cfg(any(unix, target_os = "redox"))]
|
||||||
use std::os::unix::prelude::OsStrExt;
|
use std::os::unix::prelude::OsStrExt;
|
||||||
#[cfg(target_os = "wasi")]
|
#[cfg(target_os = "wasi")]
|
||||||
@ -63,18 +62,16 @@ pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self, ()> {
|
|||||||
// An URL's path must not be empty.
|
// An URL's path must not be empty.
|
||||||
serialization.push('/');
|
serialization.push('/');
|
||||||
}
|
}
|
||||||
Ok(Self(serialization))
|
Self(serialization)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_unit_err)]
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self, ()> {
|
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Self {
|
||||||
from_file_path_windows(path.as_ref())
|
from_file_path_windows(path.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_unit_err)]
|
|
||||||
#[cfg_attr(not(windows), allow(dead_code))]
|
#[cfg_attr(not(windows), allow(dead_code))]
|
||||||
fn from_file_path_windows(path: &Path) -> Result<Self, ()> {
|
fn from_file_path_windows(path: &Path) -> Self {
|
||||||
use std::path::{Component, Prefix};
|
use std::path::{Component, Prefix};
|
||||||
|
|
||||||
fn is_windows_drive_letter(segment: &str) -> bool {
|
fn is_windows_drive_letter(segment: &str) -> bool {
|
||||||
@ -123,16 +120,15 @@ fn is_windows_drive_letter(segment: &str) -> bool {
|
|||||||
serialization.push('/');
|
serialization.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self(serialization))
|
Self(serialization)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_unit_err)]
|
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Self {
|
||||||
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Self, ()> {
|
let Self(mut serialization) = Self::from_file_path(path);
|
||||||
let Self(mut serialization) = Self::from_file_path(path)?;
|
|
||||||
if !serialization.ends_with('/') {
|
if !serialization.ends_with('/') {
|
||||||
serialization.push('/');
|
serialization.push('/');
|
||||||
}
|
}
|
||||||
Ok(Self(serialization))
|
Self(serialization)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the serialized representation of the URL as a `&str`
|
/// Returns the serialized representation of the URL as a `&str`
|
||||||
|
@ -42,8 +42,7 @@ fn workspace_for_path(path: &Path) -> WorkspaceFolder {
|
|||||||
|
|
||||||
lsp::WorkspaceFolder {
|
lsp::WorkspaceFolder {
|
||||||
name,
|
name,
|
||||||
uri: lsp::Url::from_directory_path(path)
|
uri: lsp::Url::from_directory_path(path),
|
||||||
.expect("absolute paths can be converted to `Url`s"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +202,7 @@ pub fn start(
|
|||||||
Transport::start(reader, writer, stderr, id, name.clone());
|
Transport::start(reader, writer, stderr, id, name.clone());
|
||||||
|
|
||||||
let workspace_folders = root.clone().into_iter().collect();
|
let workspace_folders = root.clone().into_iter().collect();
|
||||||
let root_uri = root.clone().map(|root| {
|
let root_uri = root.clone().map(lsp::Url::from_file_path);
|
||||||
lsp::Url::from_file_path(root).expect("absolute paths can be converted to `Url`s")
|
|
||||||
});
|
|
||||||
// `root_uri` and `workspace_folder` can be empty in case there is no workspace
|
// `root_uri` and `workspace_folder` can be empty in case there is no workspace
|
||||||
// `root_url` can not, use `workspace` as a fallback
|
// `root_url` can not, use `workspace` as a fallback
|
||||||
let root_path = root.unwrap_or(workspace);
|
let root_path = root.unwrap_or(workspace);
|
||||||
@ -743,11 +740,11 @@ pub fn will_rename(
|
|||||||
} else {
|
} else {
|
||||||
Url::from_file_path(path)
|
Url::from_file_path(path)
|
||||||
};
|
};
|
||||||
Some(url.ok()?.into_string())
|
url.into_string()
|
||||||
};
|
};
|
||||||
let files = vec![lsp::FileRename {
|
let files = vec![lsp::FileRename {
|
||||||
old_uri: url_from_path(old_path)?,
|
old_uri: url_from_path(old_path),
|
||||||
new_uri: url_from_path(new_path)?,
|
new_uri: url_from_path(new_path),
|
||||||
}];
|
}];
|
||||||
let request = self.call_with_timeout::<lsp::request::WillRenameFiles>(
|
let request = self.call_with_timeout::<lsp::request::WillRenameFiles>(
|
||||||
&lsp::RenameFilesParams { files },
|
&lsp::RenameFilesParams { files },
|
||||||
@ -777,12 +774,12 @@ pub fn did_rename(
|
|||||||
} else {
|
} else {
|
||||||
Url::from_file_path(path)
|
Url::from_file_path(path)
|
||||||
};
|
};
|
||||||
Some(url.ok()?.into_string())
|
url.into_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let files = vec![lsp::FileRename {
|
let files = vec![lsp::FileRename {
|
||||||
old_uri: url_from_path(old_path)?,
|
old_uri: url_from_path(old_path),
|
||||||
new_uri: url_from_path(new_path)?,
|
new_uri: url_from_path(new_path),
|
||||||
}];
|
}];
|
||||||
Some(self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files }))
|
Some(self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files }))
|
||||||
}
|
}
|
||||||
|
@ -106,9 +106,7 @@ async fn run(mut rx: mpsc::UnboundedReceiver<Event>) {
|
|||||||
log::warn!("LSP client was dropped: {id}");
|
log::warn!("LSP client was dropped: {id}");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let Ok(uri) = lsp::Url::from_file_path(&path) else {
|
let uri = lsp::Url::from_file_path(&path);
|
||||||
return true;
|
|
||||||
};
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Sending didChangeWatchedFiles notification to client '{}'",
|
"Sending didChangeWatchedFiles notification to client '{}'",
|
||||||
client.name()
|
client.name()
|
||||||
|
@ -1822,7 +1822,7 @@ pub fn path(&self) -> Option<&PathBuf> {
|
|||||||
|
|
||||||
/// File path as a URL.
|
/// File path as a URL.
|
||||||
pub fn url(&self) -> Option<lsp::Url> {
|
pub fn url(&self) -> Option<lsp::Url> {
|
||||||
lsp::Url::from_file_path(self.path()?).ok()
|
self.path().map(lsp::Url::from_file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uri(&self) -> Option<helix_core::Uri> {
|
pub fn uri(&self) -> Option<helix_core::Uri> {
|
||||||
|
Loading…
Reference in New Issue
Block a user