diff options
author | Gokul Soumya | 2022-02-14 16:41:53 +0000 |
---|---|---|
committer | GitHub | 2022-02-14 16:41:53 +0000 |
commit | 4c424d5ee442788b32eaaee67b4256aaa93aafa2 (patch) | |
tree | 7ea2a8e579b16400ae9573264c96b82123e1c828 /helix-term/src | |
parent | e267dc834a815ae2dd9d04c9e81fb206f81a2c99 (diff) |
Refactor language config loading (#1658)
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 52a5321f..6ba05498 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1,4 +1,7 @@ -use helix_core::{merge_toml_values, pos_at_coords, syntax, Selection}; +use helix_core::{ + config::{default_syntax_loader, user_syntax_loader}, + pos_at_coords, syntax, Selection, +}; use helix_dap::{self as dap, Payload, Request}; use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap}; use helix_view::{editor::Breakpoint, theme, Editor}; @@ -69,21 +72,6 @@ impl Application { std::sync::Arc::new(theme::Loader::new(&conf_dir, &helix_core::runtime_dir())); // load default and user config, and merge both - let builtin_err_msg = - "Could not parse built-in languages.toml, something must be very wrong"; - let def_lang_conf: toml::Value = - toml::from_slice(include_bytes!("../../languages.toml")).expect(builtin_err_msg); - let def_syn_loader_conf: helix_core::syntax::Configuration = - def_lang_conf.clone().try_into().expect(builtin_err_msg); - let user_lang_conf = std::fs::read(conf_dir.join("languages.toml")) - .ok() - .map(|raw| toml::from_slice(&raw)); - let lang_conf = match user_lang_conf { - Some(Ok(value)) => Ok(merge_toml_values(def_lang_conf, value)), - Some(err @ Err(_)) => err, - None => Ok(def_lang_conf), - }; - let true_color = config.editor.true_color || crate::true_color(); let theme = config .theme @@ -106,16 +94,14 @@ impl Application { } }); - let syn_loader_conf: helix_core::syntax::Configuration = lang_conf - .and_then(|conf| conf.try_into()) - .unwrap_or_else(|err| { - eprintln!("Bad language config: {}", err); - eprintln!("Press <ENTER> to continue with default language config"); - use std::io::Read; - // This waits for an enter press. - let _ = std::io::stdin().read(&mut []); - def_syn_loader_conf - }); + let syn_loader_conf = user_syntax_loader().unwrap_or_else(|err| { + eprintln!("Bad language config: {}", err); + eprintln!("Press <ENTER> to continue with default language config"); + use std::io::Read; + // This waits for an enter press. + let _ = std::io::stdin().read(&mut []); + default_syntax_loader() + }); let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf)); let mut editor = Editor::new( |