GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — formatter config · steipete/opencode@30e1012

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • opencode.json
  • packages/opencode/src
    • config
      • config.ts
    • format
      • formatter.ts
      • index.ts
    • tool
      • edit.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎opencode.json‎

Copy file name to clipboardExpand all lines: opencode.json
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
}
2020
}
2121
},
22+
"formatter": {
23+
"test": {
24+
"extensions": [".json"],
25+
"command": ["sed", "-i", "s/name/poop/g", "$FILE"]
26+
}
27+
},
2228
"mcp": {
2329
"context7": {
2430
"type": "remote",
Collapse file

‎packages/opencode/src/config/config.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/config/config.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ export namespace Config {
283283
z.string(),
284284
z.object({
285285
disabled: z.boolean().optional(),
286+
command: z.array(z.string()).optional(),
287+
environment: z.record(z.string(), z.string()).optional(),
288+
extensions: z.array(z.string()).optional(),
286289
}),
287290
)
288291
.optional(),
Collapse file

‎packages/opencode/src/format/formatter.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/format/formatter.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ export const clang: Info = {
129129
command: ["clang-format", "-i", "$FILE"],
130130
extensions: [".c", ".cc", ".cpp", ".cxx", ".c++", ".h", ".hh", ".hpp", ".hxx", ".h++", ".ino", ".C", ".H"],
131131
async enabled() {
132-
return Bun.which("clang-format") !== null
132+
const app = App.info()
133+
const items = await Filesystem.findUp(".clang-format", app.path.cwd, app.path.root)
134+
return items.length > 0
133135
},
134136
}
135137

Collapse file

‎packages/opencode/src/format/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/format/index.ts
+24-5Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,39 @@ import path from "path"
66

77
import * as Formatter from "./formatter"
88
import { Config } from "../config/config"
9+
import { mergeDeep } from "remeda"
910

1011
export namespace Format {
1112
const log = Log.create({ service: "format" })
1213

13-
const state = App.state("format", () => {
14+
const state = App.state("format", async () => {
1415
const enabled: Record<string, boolean> = {}
16+
const cfg = await Config.get()
17+
18+
const formatters = { ...Formatter } as Record<string, Formatter.Info>
19+
for (const [name, item] of Object.entries(cfg.formatter ?? {})) {
20+
if (item.disabled) {
21+
delete formatters[name]
22+
continue
23+
}
24+
const result: Formatter.Info = mergeDeep(formatters[name] ?? {}, {
25+
command: [],
26+
extensions: [],
27+
...item,
28+
})
29+
result.enabled = async () => true
30+
result.name = name
31+
formatters[name] = result
32+
}
1533

1634
return {
1735
enabled,
36+
formatters,
1837
}
1938
})
2039

2140
async function isEnabled(item: Formatter.Info) {
22-
const s = state()
41+
const s = await state()
2342
let status = s.enabled[item.name]
2443
if (status === undefined) {
2544
status = await item.enabled()
@@ -29,11 +48,11 @@ export namespace Format {
2948
}
3049

3150
async function getFormatter(ext: string) {
32-
const cfg = await Config.get()
51+
const formatters = await state().then((x) => x.formatters)
3352
const result = []
34-
for (const item of Object.values(Formatter)) {
53+
for (const item of Object.values(formatters)) {
54+
log.info("checking", { name: item.name, ext })
3555
if (!item.extensions.includes(ext)) continue
36-
if (cfg.formatter?.[item.name]?.disabled) continue
3756
if (!(await isEnabled(item))) continue
3857
result.push(item)
3958
}
Collapse file

‎packages/opencode/src/tool/edit.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/tool/edit.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const EditTool = Tool.define("edit", {
9696
file: filePath,
9797
})
9898
contentNew = await file.text()
99+
diff = trimDiff(createTwoFilesPatch(filePath, filePath, contentOld, contentNew))
99100
})()
100101

101102
FileTime.read(ctx.sessionID, filePath)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.