feat(erlang): Configure when the module is shown (#2346)

* feat(erlang): Configure when the module is shown

This makes it possible to configure when the erlang 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.

* Update docs/config/README.md

Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com>

Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com>
This commit is contained in:
Thomas O'Donnell
2021-02-21 13:20:14 +01:00
committed by GitHub
parent 7331e4bec6
commit 873a005c42
3 changed files with 22 additions and 15 deletions
+6
View File
@@ -8,6 +8,9 @@ pub struct ErlangConfig<'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 ErlangConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ErlangConfig<'a> {
symbol: "",
style: "bold red",
disabled: false,
detect_extensions: vec![],
detect_files: vec!["rebar.config", "erlang.mk"],
detect_folders: vec![],
}
}
}
+6 -8
View File
@@ -4,23 +4,21 @@ use crate::configs::erlang::ErlangConfig;
use crate::formatter::StringFormatter;
/// Create a module with the current Erlang version
///
/// Will display the Erlang version if any of the following criteria are met:
/// - Current directory contains a rebar.config file
/// - Current directory contains a erlang.mk file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("erlang");
let config = ErlangConfig::try_load(module.config);
let is_erlang_project = context
.try_begin_scan()?
.set_files(&["rebar.config", "erlang.mk"])
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_erlang_project {
return None;
}
let mut module = context.new_module("erlang");
let config = ErlangConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|variable, _| match variable {