@@ -398,6 +398,14 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
398398 Ok(normalize_path(&path))
399399}
400400
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)
405+ };
406+ fold_home_dir(path)
407+}
408+
401409use helix_lsp::lsp;
402410use url::Url;
403411
@@ -936,15 +944,7 @@ impl Document {
936944 }
937945
938946 pub fn relative_path(&self) -> Option<PathBuf> {
939− let cwdir = std::env::current_dir().expect("couldn't determine current directory");
940−
941− self.path.as_ref().map(|path| {
942− let mut path = path.as_path();
943− if path.is_absolute() {
944− path = path.strip_prefix(cwdir).unwrap_or(path)
945− };
946− fold_home_dir(path)
947− })
947+ self.path.as_deref().map(relative_path)
948948 }
949949
950950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {