-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use super::execute_command; | ||
use crate::error::MdsfError; | ||
|
||
#[inline] | ||
pub fn format_using_fnlfmt( | ||
snippet_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
let mut cmd = std::process::Command::new("fnlfmt"); | ||
|
||
cmd.arg(snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use schemars::JsonSchema; | ||
|
||
use super::{Lang, LanguageFormatter}; | ||
use crate::{ | ||
error::MdsfError, | ||
formatters::{fnlfmt::format_using_fnlfmt, MdsfFormatter}, | ||
}; | ||
|
||
#[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] | ||
#[cfg_attr(test, derive(Debug, PartialEq, Eq))] | ||
pub enum Fennel { | ||
#[default] | ||
#[serde(rename = "fnlfmt")] | ||
Fnlfmt, | ||
} | ||
|
||
impl Default for Lang<Fennel> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
enabled: true, | ||
formatter: MdsfFormatter::<Fennel>::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for MdsfFormatter<Fennel> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self::Single(Fennel::Fnlfmt) | ||
} | ||
} | ||
|
||
impl LanguageFormatter for Fennel { | ||
#[inline] | ||
fn format_snippet( | ||
&self, | ||
snippet_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
match self { | ||
Self::Fnlfmt => format_using_fnlfmt(snippet_path), | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Display for Fennel { | ||
#[inline] | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::Fnlfmt => write!(f, "fnlfmt"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_fennel { | ||
use super::Fennel; | ||
use crate::languages::Lang; | ||
|
||
#[test] | ||
fn it_should_be_enabled_by_default() { | ||
assert!(Lang::<Fennel>::default().enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters