@@ -398,6 +398,14 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
398 Ok(normalize_path(&path))
398 Ok(normalize_path(&path))
401+pub fn relative_path(mut path: &Path) -> PathBuf {
402+ let cwdir = std::env::current_dir().expect("couldn't determine current directory");
403+ if path.is_absolute() {
404+ path = path.strip_prefix(cwdir).unwrap_or(path)
401use helix_lsp::lsp;
409use helix_lsp::lsp;
402use url::Url;
410use url::Url;
@@ -936,15 +944,7 @@ impl Document {
938 pub fn relative_path(&self) -> Option<PathBuf> {
946 pub fn relative_path(&self) -> Option<PathBuf> {
939− let cwdir = std::env::current_dir().expect("couldn't determine current directory");
941− self.path.as_ref().map(|path| {
947+ self.path.as_deref().map(relative_path)
942− let mut path = path.as_path();
943− if path.is_absolute() {
944− path = path.strip_prefix(cwdir).unwrap_or(path)
950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {
950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {