@@ -17,6 +17,9 @@ mod state;
1717pub mod syntax;
1818mod transaction;
1919
20+static RUNTIME_DIR: once_cell::sync::Lazy<std::path::PathBuf> =
21+ once_cell::sync::Lazy::new(runtime_dir);
22+
2023pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
2124 line.chars().position(|ch| !ch.is_whitespace())
2225}
@@ -47,15 +50,26 @@ pub fn find_root(root: Option<&str>) -> Option<std::path::PathBuf> {
4750
4851#[cfg(not(embed_runtime))]
4952pub fn runtime_dir() -> std::path::PathBuf {
50− // runtime env var || dir where binary is located
51− std::env::var("HELIX_RUNTIME")
52− .map(|path| path.into())
53− .unwrap_or_else(|_| {
54− std::env::current_exe()
55− .ok()
56− .and_then(|path| path.parent().map(|path| path.to_path_buf()))
57− .unwrap()
58− })
53+ if let Ok(dir) = std::env::var("HELIX_RUNTIME") {
54+ return dir.into();
55+ }
56+
57+ const RT_DIR: &str = "runtime";
58+ let conf_dir = config_dir().join(RT_DIR);
59+ if conf_dir.exists() {
60+ return conf_dir;
61+ }
62+
63+ if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") {
64+ // this is the directory of the crate being run by cargo, we need the workspace path so we take the parent
65+ return std::path::PathBuf::from(dir).parent().unwrap().join(RT_DIR);
66+ }
67+
68+ // fallback to location of the executable being run
69+ std::env::current_exe()
70+ .ok()
71+ .and_then(|path| path.parent().map(|path| path.to_path_buf()))
72+ .unwrap()
5973}
6074
6175pub fn config_dir() -> std::path::PathBuf {