diff options
author | Shu Kutsuzawa <cappyzawa@gmail.com> | 2021-02-22 03:50:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 19:50:40 +0100 |
commit | e73581ddf00207fa0b17a07b43ac0f7785eb1811 (patch) | |
tree | 80691127184be8d90bafd20f9544ac915d001f3f /src | |
parent | 509767adc02c39f206e7f0df15920ddba1b2444e (diff) |
feat(ocaml): Configure when the module is shown (#2354)
This makes it possible to configure when the ocaml 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/ocaml.rs | 6 | ||||
-rw-r--r-- | src/modules/ocaml.rs | 19 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/configs/ocaml.rs b/src/configs/ocaml.rs index f407c6b9d..7f1dad715 100644 --- a/src/configs/ocaml.rs +++ b/src/configs/ocaml.rs @@ -8,6 +8,9 @@ pub struct OCamlConfig<'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 OCamlConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for OCamlConfig<'a> { symbol: "🐫 ", style: "bold yellow", disabled: false, + detect_extensions: vec!["opam", "ml", "mli", "re", "rei"], + detect_files: vec!["dune", "dune-project", "jbuild", "jbuild-ignore", ".merlin"], + detect_folders: vec!["_opam", "esy.lock"], } } } diff --git a/src/modules/ocaml.rs b/src/modules/ocaml.rs index 0c7bd8d7a..0b7a19dd1 100644 --- a/src/modules/ocaml.rs +++ b/src/modules/ocaml.rs @@ -4,29 +4,20 @@ use crate::configs::ocaml::OCamlConfig; use crate::formatter::StringFormatter; /// Creates a module with the current OCaml version -/// -/// Will display the OCaml version if any of the following criteria are met: -/// - Current directory contains a file with `.opam` extension or `_opam` directory -/// - Current directory contains a `esy.lock` directory -/// - Current directory contains a `dune` or `dune-project` file -/// - Current directory contains a `jbuild` or `jbuild-ignore` file -/// - Current directory contains a `.merlin` file -/// - Current directory contains a file with `.ml`, `.mli`, `.re` or `.rei` extension pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("ocaml"); + let config: OCamlConfig = OCamlConfig::try_load(module.config); let is_ocaml_project = context .try_begin_scan()? - .set_files(&["dune", "dune-project", "jbuild", "jbuild-ignore", ".merlin"]) - .set_folders(&["_opam", "esy.lock"]) - .set_extensions(&["opam", "ml", "mli", "re", "rei"]) + .set_files(&config.detect_files) + .set_folders(&config.detect_folders) + .set_extensions(&config.detect_extensions) .is_match(); if !is_ocaml_project { return None; } - let mut module = context.new_module("ocaml"); - let config: OCamlConfig = OCamlConfig::try_load(module.config); - let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|variable, _| match variable { |