Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: updated formatter picker to exclude wildcard matches if no wildc…
…ards in config
  • Loading branch information
OpeOginni committed Nov 4, 2025
commit 5fdb0d8ca18d5d9b1c07aa62b2aaea87e20444e2
33 changes: 25 additions & 8 deletions packages/opencode/src/format/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,33 @@ export namespace Format {
return status
}

async function getFormatter(ext: string) {
async function getFormatter(ext: string, fullExt: string) {
const formatters = await state().then((x) => x.formatters)
const result = []
const possibleFormatters = []

for (const item of Object.values(formatters)) {
log.info("checking", { name: item.name, ext })
if (!item.extensions.some(pattern => Wildcard.match(ext, pattern))) continue
log.info("checking", { name: item.name, ext, fullExt })

const matches = item.extensions.some(pattern => {
if (pattern.includes("*") || pattern.includes("?")) {
return Wildcard.match(fullExt, pattern)
}
return pattern === ext
})

if (!matches) continue
if (!(await isEnabled(item))) continue
result.push(item)
possibleFormatters.push(item)
}
return result

const strongFormatters = possibleFormatters.filter(formatter =>
formatter.extensions.some(pattern =>
(pattern.includes("*") || pattern.includes("?")) &&
Wildcard.match(fullExt, pattern)
)
)
if (strongFormatters.length) return strongFormatters
return possibleFormatters
}

export async function status() {
Expand All @@ -94,9 +111,9 @@ export namespace Format {
Bus.subscribe(File.Event.Edited, async (payload) => {
const file = payload.properties.file
log.info("formatting", { file })
const ext = Filesystem.getFullExt(file)
const { ext, fullExt } = Filesystem.getFullExt(file)

for (const item of await getFormatter(ext)) {
for (const item of await getFormatter(ext, fullExt)) {
log.info("running", { command: item.command })
try {
const proc = Bun.spawn({
Expand Down
7 changes: 4 additions & 3 deletions packages/opencode/src/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ export namespace Filesystem {
return result
}

export function getFullExt(filename: string): string {
export function getFullExt(filename: string): { ext: string, fullExt: string } {
const base = path.basename(filename);
const ext = path.extname(filename);
const parts = base.split(".");

if (parts.length <= 1) return "";
if (parts.length <= 1) return { ext: "", fullExt: "" };

return "." + parts.slice(1).join(".");
return { ext: ext, fullExt: "." + parts.slice(1).join(".") };
}
}