feat(elixir): Configure when module is shown (#2340)

This makes it possible to configure when the elixir 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.
This commit is contained in:
Thomas O'Donnell
2021-02-20 18:32:04 +01:00
committed by GitHub
parent 37d3425d21
commit 9313e90773
3 changed files with 35 additions and 23 deletions
+6
View File
@@ -8,6 +8,9 @@ pub struct ElixirConfig<'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 ElixirConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
symbol: "💧 ",
style: "bold purple",
disabled: false,
detect_extensions: vec![],
detect_files: vec!["mix.exs"],
detect_folders: vec![],
}
}
}
+9 -6
View File
@@ -12,11 +12,16 @@ Erlang/OTP (?P<otp>\\d+)[^\\n]+
Elixir (?P<elixir>\\d[.\\d]+).*";
/// Create a module with the current Elixir version
///
/// Will display the Elixir version if any of the following criteria are met:
/// - Current directory contains a `mix.exs` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_elixir_project = context.try_begin_scan()?.set_files(&["mix.exs"]).is_match();
let mut module = context.new_module("elixir");
let config = ElixirConfig::try_load(module.config);
let is_elixir_project = context
.try_begin_scan()?
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_elixir_project {
return None;
@@ -24,8 +29,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let versions = Lazy::new(|| get_elixir_version(context));
let mut module = context.new_module("elixir");
let config = ElixirConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {