Skip to content

Commit

Permalink
feat: add support for futhark fmt (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 14, 2025
1 parent 74087c9 commit 26bd035
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.4.0...HEAD)

- feat: add support for futhark fmt [`#609`](https://github.com/hougesen/mdsf/pull/609)
- feat: add support for wa fmt [`#608`](https://github.com/hougesen/mdsf/pull/608)
- feat: add support for selena [`#607`](https://github.com/hougesen/mdsf/pull/607)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 237 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 238 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -289,6 +289,7 @@ mdsf init
| [forge](https://github.com/foundry-rs/foundry) | A Solidity formatter | `formatter` | `solidity` |
| [fourmolu](https://hackage.haskell.org/package/fourmolu) | A formatter for Haskell source code | `formatter` | `haskell` |
| [fprettify](https://github.com/fortran-lang/fprettify) | Auto-formatter for modern Fortran source code | `formatter` | `fortran` |
| [futhark](https://futhark.readthedocs.io/en/latest/man/futhark-fmt.html) | Code formatter for the furhark programming language | `formatter` | `futhark` |
| [gci](https://github.com/daixiang0/gci) | GCI, a tool that control golang package import order and make it always deterministic | `formatter` | `go` |
| [gdformat](https://github.com/scony/godot-gdscript-toolkit) | GDScript linter | `formatter` | `gdscript` |
| [gersemi](https://github.com/blankspruce/gersemi) | A formatter to make your CMake code the real treasure | `formatter` | `cmake` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/futhark_fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_futhark_fmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("fmt");
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [CommandType::Direct("futhark")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_futhark_fmt_args(cmd.build(), file_path);
let execution_result = execute_command(cmd, file_path);

if index == commands.len() - 1 {
return execution_result;
}

if let Ok(r) = execution_result {
if !r.0 {
return Ok(r);
}
}
}

Ok((true, None))
}

#[cfg(test)]
mod test_futhark_fmt {}
9 changes: 8 additions & 1 deletion mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub mod fnlfmt;
pub mod forge_fmt;
pub mod fourmolu;
pub mod fprettify;
pub mod futhark_fmt;
pub mod gci;
pub mod gdformat;
pub mod gersemi;
Expand Down Expand Up @@ -555,6 +556,10 @@ pub enum Tooling {
/// `fprettify $PATH`
Fprettify,

#[serde(rename = "futhark:fmt")]
/// `futhark fmt $PATH`
FutharkFmt,

#[serde(rename = "gci")]
/// `gci write --skip-generated --skip-vender $PATH`
Gci,
Expand Down Expand Up @@ -1196,7 +1201,7 @@ pub enum Tooling {
VhdlStyleGuide,

#[serde(rename = "wa:fmt")]
/// `wa $PATH`
/// `wa fmt $PATH`
WaFmt,

#[serde(rename = "wfindent")]
Expand Down Expand Up @@ -1328,6 +1333,7 @@ impl Tooling {
Self::ForgeFmt => forge_fmt::run(snippet_path),
Self::Fourmolu => fourmolu::run(snippet_path),
Self::Fprettify => fprettify::run(snippet_path),
Self::FutharkFmt => futhark_fmt::run(snippet_path),
Self::Gci => gci::run(snippet_path),
Self::Gdformat => gdformat::run(snippet_path),
Self::Gersemi => gersemi::run(snippet_path),
Expand Down Expand Up @@ -1585,6 +1591,7 @@ impl AsRef<str> for Tooling {
Self::ForgeFmt => "forge_fmt",
Self::Fourmolu => "fourmolu",
Self::Fprettify => "fprettify",
Self::FutharkFmt => "futhark_fmt",
Self::Gci => "gci",
Self::Gdformat => "gdformat",
Self::Gersemi => "gersemi",
Expand Down
1 change: 1 addition & 0 deletions mdsf/src/tools/wa_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_wa_fmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("fmt");
cmd.arg(file_path);
cmd
}
Expand Down
7 changes: 6 additions & 1 deletion schemas/v0.4.0-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@
"type": "string",
"enum": ["fprettify"]
},
{
"description": "`futhark fmt $PATH`",
"type": "string",
"enum": ["futhark:fmt"]
},
{
"description": "`gci write --skip-generated --skip-vender $PATH`",
"type": "string",
Expand Down Expand Up @@ -1239,7 +1244,7 @@
"enum": ["vhdl-style-guide"]
},
{
"description": "`wa $PATH`",
"description": "`wa fmt $PATH`",
"type": "string",
"enum": ["wa:fmt"]
},
Expand Down
15 changes: 15 additions & 0 deletions tools/futhark/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "futhark",
"categories": ["formatter"],
"commands": {
"fmt": ["fmt", "$PATH"]
},
"description": "Code formatter for the furhark programming language",
"homepage": "https://futhark.readthedocs.io/en/latest/man/futhark-fmt.html",
"languages": ["futhark"],
"name": null,
"npm": null,
"php": null,
"tests": []
}
2 changes: 1 addition & 1 deletion tools/wa/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"binary": "wa",
"categories": ["formatter"],
"commands": {
"fmt": ["$PATH"]
"fmt": ["fmt", "$PATH"]
},
"description": "Formatter for the wa programming language",
"homepage": "https://github.com/wa-lang/wa/",
Expand Down

0 comments on commit 26bd035

Please sign in to comment.