aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/config.rs')
-rw-r--r--helix-core/src/config.rs45
1 files changed, 40 insertions, 5 deletions
diff --git a/helix-core/src/config.rs b/helix-core/src/config.rs
index 2076fc22..27cd4e29 100644
--- a/helix-core/src/config.rs
+++ b/helix-core/src/config.rs
@@ -1,10 +1,45 @@
-/// Syntax configuration loader based on built-in languages.toml.
-pub fn default_syntax_loader() -> crate::syntax::Configuration {
+use crate::syntax::{Configuration, Loader, LoaderError};
+
+/// Language configuration based on built-in languages.toml.
+pub fn default_lang_config() -> Configuration {
helix_loader::config::default_lang_config()
.try_into()
- .expect("Could not serialize built-in languages.toml")
+ .expect("Could not deserialize built-in languages.toml")
}
-/// Syntax configuration loader based on user configured languages.toml.
-pub fn user_syntax_loader() -> Result<crate::syntax::Configuration, toml::de::Error> {
+
+/// Language configuration loader based on built-in languages.toml.
+pub fn default_lang_loader() -> Loader {
+ Loader::new(default_lang_config()).expect("Could not compile loader for default config")
+}
+
+#[derive(Debug)]
+pub enum LanguageLoaderError {
+ DeserializeError(toml::de::Error),
+ LoaderError(LoaderError),
+}
+
+impl std::fmt::Display for LanguageLoaderError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::DeserializeError(err) => write!(f, "Failed to parse language config: {err}"),
+ Self::LoaderError(err) => write!(f, "Failed to compile language config: {err}"),
+ }
+ }
+}
+
+impl std::error::Error for LanguageLoaderError {}
+
+/// Language configuration based on user configured languages.toml.
+pub fn user_lang_config() -> Result<Configuration, toml::de::Error> {
helix_loader::config::user_lang_config()?.try_into()
}
+
+/// Language configuration loader based on user configured languages.toml.
+pub fn user_lang_loader() -> Result<Loader, LanguageLoaderError> {
+ let config: Configuration = helix_loader::config::user_lang_config()
+ .map_err(LanguageLoaderError::DeserializeError)?
+ .try_into()
+ .map_err(LanguageLoaderError::DeserializeError)?;
+
+ Loader::new(config).map_err(LanguageLoaderError::LoaderError)
+}