Skip to content

Commit 19a3ca1

Browse files
committed
use a constant for the lang config filename
1 parent c9b564c commit 19a3ca1

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

book/src/languages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ auto-format = false
1414

1515
# Project-level Configuration
1616

17-
You can create a `.helix` directory either in the current working directory or in the same directory as `.git`. Then you can write a `languages.toml` file that will overwrite both global and default language settings.
17+
You can create a `.helix` folder containing a `languages.toml` folder in either the CWD or root directory. If `.helix` exists in both folders, the CWD config will override the root config. The local config overrides both global and default language settings.

helix-core/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ pub fn config_dir() -> std::path::PathBuf {
9595
path
9696
}
9797

98-
/// First looks for the local `.helix` directory in CWD. If it can't find it, then
99-
/// it searches for it within the root `.git` directory. Otherwise, it uses the CWD
100-
/// to avoid an unwrap.
98+
/// Looks for the `.helix` config directory in the root directory, or otherwise in the
99+
/// current working directory.
101100
pub fn local_config_dir() -> std::path::PathBuf {
102101
let root = find_root(None)
103102
.unwrap_or_else(|| std::env::current_dir().expect("unable to determine current directory"));

helix-term/src/application.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,18 @@ impl Application {
9292
Err(err) => return Err(Error::new(err)),
9393
};
9494

95+
const LANG_CONFIG_FILENAME: &str = "languages.toml";
96+
9597
// Config override order: local (cwd) -> local (root) -> global -> default.
9698
// Read and parse the `languages.toml` files as TOML objects.
9799
let default_lang_config: toml::Value =
98-
toml::from_slice(include_bytes!("../../languages.toml"))
99-
.expect("failed to read the default `languages.toml`");
100+
toml::from_slice(include_bytes!("../../languages.toml")).unwrap_or_else(|_| {
101+
panic!("failed to read the default `{}`", LANG_CONFIG_FILENAME)
102+
});
100103
let lang_config: toml::Value = {
101-
let local_cwd_config = load_lang_config(cwd.join(".helix/languages.toml"))?;
102-
let local_root_config = load_lang_config(local_config_dir.join("languages.toml"))?;
103-
let global_config = load_lang_config(config_dir.join("languages.toml"))?;
104+
let local_cwd_config = load_lang_config(cwd.join(".helix").join(LANG_CONFIG_FILENAME))?;
105+
let local_root_config = load_lang_config(local_config_dir.join(LANG_CONFIG_FILENAME))?;
106+
let global_config = load_lang_config(config_dir.join(LANG_CONFIG_FILENAME))?;
104107
[
105108
local_root_config,
106109
global_config,
@@ -113,7 +116,7 @@ impl Application {
113116
// Convert previous `toml::Value`s into the config type.
114117
let default_syn_loader_config: helix_core::syntax::Configuration = default_lang_config
115118
.try_into()
116-
.expect("failed to parse the default `languages.toml`");
119+
.unwrap_or_else(|_| panic!("failed to parse the default `{}`", LANG_CONFIG_FILENAME));
117120
let syn_loader_config: helix_core::syntax::Configuration =
118121
lang_config.try_into().unwrap_or_else(|err| {
119122
eprintln!("Bad language config: {}", err);

0 commit comments

Comments
 (0)