Repository: dprint/dprint (language: rust)

Issue:
Give option to extend from relative path from home with ~
I would like to be able to extend from my global dprint config file, which is at `~/.dprint.json`, so that I can add properties to it; however, when I do so, it doesn't recognize the `~` syntax, which means I'm forced to put an absolute path with `/home/my username/.dprint.json`

This is inconvenient, as I want to be able to use the same config files on the multiple machines I use, which don't have the same username, or even the same OS (I also use windows sometimes)

Is there any way you could make the `~` point to $HOME?

Example of usage:
```json
{
    "extends": "/home/<username>/.dprint.json", // would ideally be ~/.dprint.json
    "json": {
        "associations": ["dot_dprint.json.tmpl"]
    }
}
```


Discussion / hints:

Fix patch:
diff --git a/crates/dprint/src/environment/environment.rs b/crates/dprint/src/environment/environment.rs
index 06f55826f..11bd22afa 100644
--- a/crates/dprint/src/environment/environment.rs
+++ b/crates/dprint/src/environment/environment.rs
@@ -106,6 +106,7 @@ pub trait Environment: Clone + Send + Sync + UrlDownloader + 'static {
     total_size: usize,
   ) -> TResult;
   fn get_cache_dir(&self) -> CanonicalizedPathBuf;
+  fn get_home_dir(&self) -> Option<CanonicalizedPathBuf>;
   /// Gets the CPU architecture.
   fn cpu_arch(&self) -> String;
   /// Gets the operating system.
diff --git a/crates/dprint/src/environment/real_environment.rs b/crates/dprint/src/environment/real_environment.rs
index 908dcb6e3..8724111eb 100644
--- a/crates/dprint/src/environment/real_environment.rs
+++ b/crates/dprint/src/environment/real_environment.rs
@@ -271,6 +271,10 @@ impl Environment for RealEnvironment {
     (*CACHE_DIR.as_ref().unwrap()).clone()
   }
 
+  fn get_home_dir(&self) -> Option<CanonicalizedPathBuf> {
+    dirs::home_dir().map(|path| self.canonicalize(path).unwrap())
+  }
+
   fn cpu_arch(&self) -> String {
     std::env::consts::ARCH.to_string()
   }
diff --git a/crates/dprint/src/utils/resolve_url_or_file_path.rs b/crates/dprint/src/utils/resolve_url_or_file_path.rs
index 21979817d..a1980976c 100644
--- a/crates/dprint/src/utils/resolve_url_or_file_path.rs
+++ b/crates/dprint/src/utils/resolve_url_or_file_path.rs
@@ -101,6 +101,17 @@ pub fn resolve_url_or_file_path_to_path_source(url_or_file_path: &str, base: &Pa
       }
       return Ok(PathSource::new_remote(url));
     }
+  } else if url_or_file_path.starts_with("~/") {
+    // handle home directory
+    match environment.get_home_dir() {
+      Some(home_dir) => {
+        if url_or_file_path.len() < 4 {
+          return Ok(PathSource::new_local(environment.canonicalize(home_dir)?));
+        }
+        return Ok(PathSource::new_local(environment.canonicalize(home_dir.join(&url_or_file_path[2..]))?));
+      }
+      None => bail!("Failed to get home directory path"),
+    }
   }
 
   Ok(match base {


Test patch:
diff --git a/crates/dprint/src/environment/test_environment.rs b/crates/dprint/src/environment/test_environment.rs
index a0445497e..94d51ff8c 100644
--- a/crates/dprint/src/environment/test_environment.rs
+++ b/crates/dprint/src/environment/test_environment.rs
@@ -478,6 +478,10 @@ impl Environment for TestEnvironment {
     self.canonicalize("/cache").unwrap()
   }
 
+  fn get_home_dir(&self) -> Option<CanonicalizedPathBuf> {
+    self.canonicalize("/home").ok()
+  }
+
   fn cpu_arch(&self) -> String {
     self.cpu_arch.lock().clone()
   }