diff options
author | Shu Kutsuzawa <cappyzawa@gmail.com> | 2021-02-21 21:21:20 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 13:21:20 +0100 |
commit | 4651060999635d654775e9b1d2d7c851d9c3fe58 (patch) | |
tree | f834326f2e66f364ddf0054abb298fd971371166 /src | |
parent | 873a005c4203e1359fc8d2d4548c4e8993262fe7 (diff) |
feat(nim): Configure when the module is shown (#2347)
This makes it possible to configure when the nim 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/nim.rs | 6 | ||||
-rw-r--r-- | src/modules/nim.rs | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/configs/nim.rs b/src/configs/nim.rs index 752b01783..1e67746bb 100644 --- a/src/configs/nim.rs +++ b/src/configs/nim.rs @@ -8,6 +8,9 @@ pub struct NimConfig<'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 NimConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for NimConfig<'a> { symbol: "👑 ", style: "yellow bold", disabled: false, + detect_extensions: vec!["nim", "nims", "nimble"], + detect_files: vec!["nim.cfg"], + detect_folders: vec![], } } } diff --git a/src/modules/nim.rs b/src/modules/nim.rs index 75af863c3..f7bea7bac 100644 --- a/src/modules/nim.rs +++ b/src/modules/nim.rs @@ -4,24 +4,20 @@ use crate::configs::nim::NimConfig; use crate::formatter::StringFormatter; /// Creates a module with the current Nim version -/// -/// Will display the Nim version if any of the following criteria are met: -/// - The current directory contains a file with extension `.nim`, `.nims`, or `.nimble` -/// - The current directory contains a `nim.cfg` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("nim"); + let config = NimConfig::try_load(module.config); let is_nim_project = context .try_begin_scan()? - .set_files(&["nim.cfg"]) - .set_extensions(&["nim", "nims", "nimble"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_files) .is_match(); if !is_nim_project { return None; } - let mut module = context.new_module("nim"); - let config = NimConfig::try_load(module.config); - let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var { |