Repository navigation
fix(format): look up a built-in formatter by its published name - #46869
devYRPauli wants to merge 1 commit into
Conversation
The config lookup read Formatter[name] with the config key, which is the module's export identifier. Three built-ins publish a different name: clang-format exports as clang, air as rlang and uv as uvformat. For those three the lookup returned undefined, so the entry lost the built-in extensions and its enabled check became a command that does not exist. Any override other than disabled turned the formatter off. Key the built-ins by Info.name, which is the name the docs publish, the name status() reports and the key formatters already uses.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
|
This still reproduces on dev at 907b3bc. Executing the current formatter initialization with empty overrides for clang-format, air and uv gives each an empty extension list and disables it. This PR's name-based lookup preserves all three definitions. Could you reopen it so I can refresh and retest the branch? |
Issue for this PR
Closes #46868
Type of change
What does this PR do?
packages/opencode/src/format/index.ts:134looked up a built-in formatter withFormatter[name as keyof typeof Formatter], wherenameis the config key. That reads the module's export identifier. Three built-ins publish a different name:docs/formatters.mdxpublishes itclang-formatclangairrlanguvuvformatFor those three the lookup returned
undefined. The entry was then built frombuiltIn ?? { extensions: [] }, andenabledbecameasync () => info.command ?? false. With nocommandin the config that check always returnsfalse, and the built-in extensions were replaced by an empty list. So any override other thandisabledturned the formatter off, with no error.The published name is the correct key.
formattersis already keyed byitem.nameone block above,status()reportsitem.name, and the docs table listsclang-format,airanduv. The docs also say you can configure a built-in withenvironmentorextensions, which is the case that broke.This keys the built-ins by
Info.nameand reads that map. The cast is what hid the defect, so it is gone with it.One behaviour change beyond the fix. Writing the export identifier, for example
"clang": {}, no longer resolves to the built-in. That spelling is not in the docs. Before this change it created a second entry alongsideclang-format, so the formatter ran twice on the same file. It now behaves like any other unknown key: a custom formatter that needs its owncommand.How did you verify your code works?
Two cases added to
packages/opencode/test/format/format.test.ts.The first configures
clang-format,airanduvwith an empty override and assertsstatus()still reports each built-in's extensions.The second is end to end. It points
Formatter.clangat a scratch extension and a command that appendsC. It restores the formatter afterwards, the way the existing parallel case does, then writes a file and callsFormat.file().With the source change reverted and both tests kept, exactly those two fail and the other 11 pass:
Screenshots / recordings
Not a UI change.
Checklist