From d4885ae1743ceccef948b7e758741822308f08c6 Mon Sep 17 00:00:00 2001 From: amirlan Date: Mon, 25 May 2026 23:40:02 +0500 Subject: [PATCH 1/2] feat(format): add formatters for Lua, Swift, Scala, Typst, and C# MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add five formatters for languages that were already recognized in the language extension map but had no formatter support: - stylua (.lua) — formats Lua files, respects .stylua.toml if present - swiftformat (.swift) — standard Swift formatter - scalafmt (.scala) — requires .scalafmt.conf in project tree - typst fmt (.typ, .typc) — built-in Typst formatter - csharpier (.cs) — installed via dotnet-csharpier global tool --- packages/opencode/src/format/formatter.ts | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/opencode/src/format/formatter.ts b/packages/opencode/src/format/formatter.ts index 27b28c37bcf6..998c5642fbe0 100644 --- a/packages/opencode/src/format/formatter.ts +++ b/packages/opencode/src/format/formatter.ts @@ -402,3 +402,54 @@ export const dfmt: Info = { return [match, "-i", "$FILE"] }, } + +export const stylua: Info = { + name: "stylua", + extensions: [".lua"], + async enabled() { + const match = which("stylua") + if (!match) return false + return [match, "$FILE"] + }, +} + +export const swiftformat: Info = { + name: "swiftformat", + extensions: [".swift"], + async enabled() { + const match = which("swiftformat") + if (!match) return false + return [match, "$FILE"] + }, +} + +export const scalafmt: Info = { + name: "scalafmt", + extensions: [".scala"], + async enabled(context) { + if (!which("scalafmt")) return false + const items = await Filesystem.findUp(".scalafmt.conf", context.directory, context.worktree) + if (items.length > 0) return ["scalafmt", "$FILE"] + return false + }, +} + +export const typstfmt: Info = { + name: "typst", + extensions: [".typ", ".typc"], + async enabled() { + const match = which("typst") + if (!match) return false + return [match, "fmt", "$FILE"] + }, +} + +export const csharpier: Info = { + name: "csharpier", + extensions: [".cs"], + async enabled() { + const match = which("dotnet-csharpier") + if (!match) return false + return [match, "$FILE"] + }, +} From e052df6a6d5fe04d5484871179cd0b7c78dea93d Mon Sep 17 00:00:00 2001 From: amirlan Date: Mon, 25 May 2026 23:47:07 +0500 Subject: [PATCH 2/2] docs(format): add stylua, swiftformat, scalafmt, typst, csharpier to formatter table --- packages/web/src/content/docs/formatters.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/web/src/content/docs/formatters.mdx b/packages/web/src/content/docs/formatters.mdx index 58b63fa34888..0f1f830285e7 100644 --- a/packages/web/src/content/docs/formatters.mdx +++ b/packages/web/src/content/docs/formatters.mdx @@ -18,6 +18,7 @@ OpenCode comes with several built-in formatters for popular languages and framew | cargofmt | .rs | `cargo fmt` command available | | clang-format | .c, .cpp, .h, .hpp, .ino, and [more](https://clang.llvm.org/docs/ClangFormat.html) | `.clang-format` config file | | cljfmt | .clj, .cljs, .cljc, .edn | `cljfmt` command available | +| csharpier | .cs | `dotnet-csharpier` command available | | dart | .dart | `dart` command available | | dfmt | .d | `dfmt` command available | | gleam | .gleam | `gleam` command available | @@ -34,9 +35,13 @@ OpenCode comes with several built-in formatters for popular languages and framew | rubocop | .rb, .rake, .gemspec, .ru | `rubocop` command available | | ruff | .py, .pyi | `ruff` command available with config | | rustfmt | .rs | `rustfmt` command available | +| scalafmt | .scala | `scalafmt` command available and `.scalafmt.conf` config file | | shfmt | .sh, .bash | `shfmt` command available | | standardrb | .rb, .rake, .gemspec, .ru | `standardrb` command available | +| stylua | .lua | `stylua` command available | +| swiftformat | .swift | `swiftformat` command available | | terraform | .tf, .tfvars | `terraform` command available | +| typst | .typ, .typc | `typst` command available | | uv | .py, .pyi | `uv` command available | | zig | .zig, .zon | `zig` command available |