-
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.
feat(assembly): support asmfmt (#250)
- Loading branch information
Showing
8 changed files
with
145 additions
and
11 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_asmfmt( | ||
file_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
let mut cmd = std::process::Command::new("asmfmt"); | ||
|
||
cmd.arg("-w").arg(file_path); | ||
|
||
execute_command(&mut cmd, file_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::{asmfmt::format_using_asmfmt, MdsfFormatter}, | ||
}; | ||
|
||
#[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] | ||
#[cfg_attr(test, derive(Debug, PartialEq, Eq))] | ||
pub enum Assembly { | ||
#[default] | ||
#[serde(rename = "asmfmt")] | ||
Asmfmt, | ||
} | ||
|
||
impl Default for Lang<Assembly> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
enabled: true, | ||
formatter: MdsfFormatter::<Assembly>::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for MdsfFormatter<Assembly> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self::Single(Assembly::Asmfmt) | ||
} | ||
} | ||
|
||
impl LanguageFormatter for Assembly { | ||
#[inline] | ||
fn format_snippet( | ||
&self, | ||
snippet_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
match self { | ||
Self::Asmfmt => format_using_asmfmt(snippet_path), | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Display for Assembly { | ||
#[inline] | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::Asmfmt => write!(f, "asmfmt"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_assembly { | ||
use super::Assembly; | ||
use crate::languages::Lang; | ||
|
||
#[test] | ||
fn it_should_be_enabled_by_default() { | ||
assert!(Lang::<Assembly>::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