mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
ignore: refactoring
This commit is contained in:
parent
463257e7e4
commit
1fdb326aa7
3 changed files with 18 additions and 20 deletions
|
@ -1,7 +0,0 @@
|
|||
export interface Definition {
|
||||
name: string
|
||||
command: string[]
|
||||
environment?: Record<string, string>
|
||||
extensions: string[]
|
||||
enabled(): Promise<boolean>
|
||||
}
|
|
@ -1,8 +1,15 @@
|
|||
import { App } from "../app/app"
|
||||
import { BunProc } from "../bun"
|
||||
import type { Definition } from "./definition"
|
||||
|
||||
export const gofmt: Definition = {
|
||||
export interface Info {
|
||||
name: string
|
||||
command: string[]
|
||||
environment?: Record<string, string>
|
||||
extensions: string[]
|
||||
enabled(): Promise<boolean>
|
||||
}
|
||||
|
||||
export const gofmt: Info = {
|
||||
name: "gofmt",
|
||||
command: ["gofmt", "-w", "$FILE"],
|
||||
extensions: [".go"],
|
||||
|
@ -11,7 +18,7 @@ export const gofmt: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const mix: Definition = {
|
||||
export const mix: Info = {
|
||||
name: "mix",
|
||||
command: ["mix", "format", "$FILE"],
|
||||
extensions: [".ex", ".exs", ".eex", ".heex", ".leex", ".neex", ".sface"],
|
||||
|
@ -20,7 +27,7 @@ export const mix: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const prettier: Definition = {
|
||||
export const prettier: Info = {
|
||||
name: "prettier",
|
||||
command: [BunProc.which(), "run", "prettier", "--write", "$FILE"],
|
||||
environment: {
|
||||
|
@ -75,7 +82,7 @@ export const prettier: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const zig: Definition = {
|
||||
export const zig: Info = {
|
||||
name: "zig",
|
||||
command: ["zig", "fmt", "$FILE"],
|
||||
extensions: [".zig", ".zon"],
|
||||
|
@ -84,7 +91,7 @@ export const zig: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const clang: Definition = {
|
||||
export const clang: Info = {
|
||||
name: "clang-format",
|
||||
command: ["clang-format", "-i", "$FILE"],
|
||||
extensions: [
|
||||
|
@ -107,7 +114,7 @@ export const clang: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const ktlint: Definition = {
|
||||
export const ktlint: Info = {
|
||||
name: "ktlint",
|
||||
command: ["ktlint", "-F", "$FILE"],
|
||||
extensions: [".kt", ".kts"],
|
||||
|
@ -116,7 +123,7 @@ export const ktlint: Definition = {
|
|||
},
|
||||
}
|
||||
|
||||
export const ruff: Definition = {
|
||||
export const ruff: Info = {
|
||||
name: "ruff",
|
||||
command: ["ruff", "format", "$FILE"],
|
||||
extensions: [".py", ".pyi"],
|
|
@ -4,9 +4,7 @@ import { File } from "../file"
|
|||
import { Log } from "../util/log"
|
||||
import path from "path"
|
||||
|
||||
import type { Definition } from "./definition"
|
||||
|
||||
import * as Formatters from "./formatters"
|
||||
import * as Formatter from "./formatter"
|
||||
|
||||
export namespace Format {
|
||||
const log = Log.create({ service: "format" })
|
||||
|
@ -19,7 +17,7 @@ export namespace Format {
|
|||
}
|
||||
})
|
||||
|
||||
async function isEnabled(item: Definition) {
|
||||
async function isEnabled(item: Formatter.Info) {
|
||||
const s = state()
|
||||
let status = s.enabled[item.name]
|
||||
if (status === undefined) {
|
||||
|
@ -31,7 +29,7 @@ export namespace Format {
|
|||
|
||||
async function getFormatter(ext: string) {
|
||||
const result = []
|
||||
for (const item of Object.values(Formatters)) {
|
||||
for (const item of Object.values(Formatter)) {
|
||||
if (!item.extensions.includes(ext)) continue
|
||||
if (!isEnabled(item)) continue
|
||||
result.push(item)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue