fix: Make path absolute before normalizing

:open ../file.txt failed before because .. would be stripped
imgbot
Blaž Hrastnik 3 years ago
parent b72c6204e5
commit 48481db8ca

@ -70,7 +70,6 @@ pub enum IndentStyle {
} }
pub struct Document { pub struct Document {
// rope + selection
pub(crate) id: DocumentId, pub(crate) id: DocumentId,
text: Rope, text: Rope,
pub(crate) selections: HashMap<ViewId, Selection>, pub(crate) selections: HashMap<ViewId, Selection>,
@ -408,12 +407,13 @@ pub fn normalize_path(path: &Path) -> PathBuf {
/// This function is used instead of `std::fs::canonicalize` because we don't want to verify /// 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. /// here if the path exists, just normalize it's components.
pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> { pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
let normalized = normalize_path(path); let path = if path.is_relative() {
if normalized.is_absolute() { std::env::current_dir().map(|current_dir| current_dir.join(path))?
Ok(normalized)
} else { } else {
std::env::current_dir().map(|current_dir| current_dir.join(normalized)) path.to_path_buf()
} };
Ok(normalize_path(&path))
} }
use helix_lsp::lsp; use helix_lsp::lsp;

Loading…
Cancel
Save