diff options
author | Thomas O'Donnell <andytom@users.noreply.github.com> | 2021-02-20 18:33:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-20 18:33:00 +0100 |
commit | 71b6fc17777bd587199a6c1b2c7e30e1a87535f7 (patch) | |
tree | d105d1a287228fbc957b9724c47384fdc2227474 /src | |
parent | 9313e90773c8536e520bb34750345d7e4d4a6946 (diff) |
feat(elm): Configure when the module is shown (#2341)
This makes it possible to configure when the elm module is shown
based on the contents of a directory. This should make it possible to
be a lot more granular when configuring the module.
Diffstat (limited to 'src')
-rw-r--r-- | src/configs/elm.rs | 6 | ||||
-rw-r--r-- | src/modules/elm.rs | 19 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/configs/elm.rs b/src/configs/elm.rs index 17dc35686..801622cf4 100644 --- a/src/configs/elm.rs +++ b/src/configs/elm.rs @@ -8,6 +8,9 @@ pub struct ElmConfig<'a> { pub symbol: &'a str, pub style: &'a str, pub disabled: bool, + pub detect_extensions: Vec<&'a str>, + pub detect_files: Vec<&'a str>, + pub detect_folders: Vec<&'a str>, } impl<'a> RootModuleConfig<'a> for ElmConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ElmConfig<'a> { symbol: "🌳 ", style: "cyan bold", disabled: false, + detect_extensions: vec!["elm"], + detect_files: vec!["elm.json", "elm-package.json", ".elm-version"], + detect_folders: vec!["elm-stuff"], } } } diff --git a/src/modules/elm.rs b/src/modules/elm.rs index b3ee43380..7ebd848f4 100644 --- a/src/modules/elm.rs +++ b/src/modules/elm.rs @@ -4,28 +4,21 @@ use crate::configs::elm::ElmConfig; use crate::formatter::StringFormatter; /// Creates a module with the current Elm version -/// -/// Will display the Elm version if any of the following criteria are met: -/// - The current directory contains a `elm.json` file -/// - The current directory contains a `elm-package.json` file -/// - The current directory contains a `.elm-version` file -/// - The current directory contains a `elm-stuff` folder -/// - The current directory contains a `*.elm` files pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("elm"); + let config: ElmConfig = ElmConfig::try_load(module.config); + let is_elm_project = context .try_begin_scan()? - .set_files(&["elm.json", "elm-package.json", ".elm-version"]) - .set_extensions(&["elm"]) - .set_folders(&["elm-stuff"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) .is_match(); if !is_elm_project { return None; } - let mut module = context.new_module("elm"); - let config: ElmConfig = ElmConfig::try_load(module.config); - let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var { |