@@ -49,6 +49,16 @@ pub struct Application {
49
49
lsp_progress : LspProgressMap ,
50
50
}
51
51
52
+ fn load_lang_config ( path : std:: path:: PathBuf ) -> Result < toml:: Value , Error > {
53
+ match std:: fs:: read ( & path) {
54
+ Ok ( config) => Ok ( toml:: from_slice ( & config) . unwrap ( ) ) ,
55
+ Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
56
+ Ok ( toml:: Value :: Table ( toml:: value:: Table :: default ( ) ) )
57
+ }
58
+ Err ( err) => Err ( Error :: new ( err) ) ,
59
+ }
60
+ }
61
+
52
62
impl Application {
53
63
pub fn new ( args : Args , mut config : Config ) -> Result < Self , Error > {
54
64
use helix_view:: editor:: Action ;
@@ -57,36 +67,26 @@ impl Application {
57
67
// `local_config_dir` is a `.helix` folder within the projec directory.
58
68
let config_dir = helix_core:: config_dir ( ) ;
59
69
let local_config_dir = helix_core:: local_config_dir ( ) ;
70
+ let cwd = std:: env:: current_dir ( ) . expect ( "unable to determine current directory" ) ;
60
71
61
- // Config override order: local -> global -> default.
72
+ // Config override order: local (cwd) -> local (root) -> global -> default.
62
73
// Read and parse the `languages.toml` files as TOML objects.
63
74
let default_lang_config: toml:: Value =
64
75
toml:: from_slice ( include_bytes ! ( "../../languages.toml" ) )
65
76
. expect ( "failed to read the default `languages.toml`" ) ;
66
- let lang_config =
67
- {
68
- let local_config = match std:: fs:: read ( local_config_dir. join ( "languages.toml" ) ) {
69
- Ok ( config) => toml:: from_slice ( & config)
70
- . expect ( "failed to read the local `languages.toml`" ) ,
71
- Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
72
- toml:: Value :: Table ( toml:: value:: Table :: default ( ) )
73
- }
74
- Err ( err) => return Err ( Error :: new ( err) ) ,
75
- } ;
76
- let global_config = match std:: fs:: read ( config_dir. join ( "languages.toml" ) ) {
77
- Ok ( config) => toml:: from_slice ( & config)
78
- . expect ( "failed to read the global `languages.toml`" ) ,
79
- Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
80
- toml:: Value :: Table ( toml:: value:: Table :: default ( ) )
81
- }
82
- Err ( err) => return Err ( Error :: new ( err) ) ,
83
- } ;
77
+ let lang_config = {
78
+ let local_cwd_config = load_lang_config ( cwd. join ( ".helix/languages.toml" ) ) ?;
79
+ let local_root_config = load_lang_config ( local_config_dir. join ( "languages.toml" ) ) ?;
80
+ let global_config = load_lang_config ( config_dir. join ( "languages.toml" ) ) ?;
84
81
82
+ merge_toml_values (
83
+ default_lang_config. clone ( ) ,
85
84
merge_toml_values (
86
- default_lang_config. clone ( ) ,
87
- merge_toml_values ( global_config, local_config) ,
88
- )
89
- } ;
85
+ global_config,
86
+ merge_toml_values ( local_root_config, local_cwd_config) ,
87
+ ) ,
88
+ )
89
+ } ;
90
90
91
91
// Convert previous `toml::Value`s into the config type.
92
92
let default_syn_loader_config: helix_core:: syntax:: Configuration = default_lang_config
0 commit comments