Perf(purescript): Lazy eval purescript (#2191)

* perf(purescript): evaluate version lazily

* fix(purescript): update format string; update tests

Co-authored-by: Moritz Vetter <mv@3yourmind.com>
This commit is contained in:
Moritz Vetter 2021-01-22 18:01:54 +01:00 committed by GitHub
parent 499e0357b0
commit 60be1e9540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -2000,12 +2000,12 @@ The module will be shown if any of the following conditions are met:
### Options
| Option | Default | Description |
| ---------- | ---------------------------------- | ------------------------------------------------------------ |
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
| `symbol` | `"<=> "` | The symbol used before displaying the version of PureScript. |
| `style` | `"bold white"` | The style for the module. |
| `disabled` | `false` | Disables the `purescript` module. |
| Option | Default | Description |
| ---------- | ------------------------------------ | ------------------------------------------------------------ |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `symbol` | `"<=> "` | The symbol used before displaying the version of PureScript. |
| `style` | `"bold white"` | The style for the module. |
| `disabled` | `false` | Disables the `purescript` module. |
### Variables

View File

@ -13,7 +13,7 @@ pub struct PureScriptConfig<'a> {
impl<'a> RootModuleConfig<'a> for PureScriptConfig<'a> {
fn new() -> Self {
PureScriptConfig {
format: "via [$symbol$version]($style) ",
format: "via [$symbol($version )]($style)",
symbol: "<=> ",
style: "bold white",
disabled: false,

View File

@ -20,8 +20,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
let purs_version = utils::exec_cmd("purs", &["--version"])?.stdout;
let mut module = context.new_module("purescript");
let config: PureScriptConfig = PureScriptConfig::try_load(module.config);
@ -36,7 +34,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
"version" => Some(Ok(format!("v{}", purs_version.trim()))),
"version" => {
let purs_version = utils::exec_cmd("purs", &["--version"])?.stdout;
Some(Ok(format!("v{}", purs_version.trim())))
}
_ => None,
})
.parse(None)
@ -75,7 +76,7 @@ mod tests {
File::create(dir.path().join("Main.purs"))?.sync_all()?;
let actual = ModuleRenderer::new("purescript").path(dir.path()).collect();
let expected = Some(format!("via {} ", Color::White.bold().paint("<=> v0.13.5")));
let expected = Some(format!("via {}", Color::White.bold().paint("<=> v0.13.5 ")));
assert_eq!(expected, actual);
dir.close()
}
@ -86,7 +87,7 @@ mod tests {
File::create(dir.path().join("spago.dhall"))?.sync_all()?;
let actual = ModuleRenderer::new("purescript").path(dir.path()).collect();
let expected = Some(format!("via {} ", Color::White.bold().paint("<=> v0.13.5")));
let expected = Some(format!("via {}", Color::White.bold().paint("<=> v0.13.5 ")));
assert_eq!(expected, actual);
dir.close()
}