feat(config): accept comments and trailing commas in programa.json#127
Merged
Conversation
Config parsing now runs through a shared JSONCParser before decoding, so
hand-edited ~/.config/programa/programa.json and project-local
programa.json/cmux.json files can use // and /* */ comments and trailing
commas without breaking. This fixes a real parse failure a user hit on
their ~/.config/cmux/cmux.json (a stray comment triggered "Unexpected
character '/'").
The parser also replaces the private, less-robust copy that lived inside
ProgramaSettingsFileStore.swift (settings.json parsing), so both config
surfaces now share one implementation with encoding detection and
unterminated-comment detection.
Ported from upstream cmux commit 4d0b1dbd1 ("Make cmux.json the canonical
settings file (#3409)"), parser and config-merge logic only. The
settings-window UI redesign that shipped in the same upstream commit is
out of scope here and was not ported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Your
programa.json(and legacycmux.json) config files can now have comments in them. If you write// dev commandsabove a block, or leave a trailing comma after copy-pasting a command entry, the config now loads instead of silently failing. This came from a real parse error a user hit on their own~/.config/cmux/cmux.json.Details
Sources/JSONCParser.swift: a shared, string-literal-aware preprocessor that strips//and/* */comments and trailing commas before handing the file toJSONDecoder. Also handles a BOM and non-UTF8 text encodings, and reports an error for an unterminated block comment instead of silently truncating the file.Sources/ProgramaConfig.swift:ProgramaConfigStore.parseConfig(at:)now runs the file throughJSONCParser.preprocessbefore decoding, with its own error log line so a JSONC syntax problem is distinguishable from a schema problem.Sources/ProgramaSettingsFileStore.swifthad its own, older, private copy of this exact parser (used forsettings.json). Removed the duplicate and pointed it at the shared one, so both config surfaces get the same (now more robust) behavior for free.ProgramaConfigJSONCDecodingTestsinprogramaTests/ProgramaConfigTests.swift— comments (line + block), trailing commas (array + object), mixed comments/commas, comment-like text inside strings, BOM handling, and error cases (unterminated block comment, comment-only file, malformed JSON after stripping). Plain JSON without any JSONC extras is also covered to confirm nothing regresses there.Scope
This ports the parser and config-merge logic from upstream cmux commit
4d0b1dbd1("Make cmux.json the canonical settings file (#3409)"). It explicitly does not port the settings-window UI redesign that shipped in the same upstream commit — that's a separate, larger feature (unifying settings.json/cmux.json/UI) outside this change's scope.Testing
```
PROGRAMA_SKIP_ZIG_BUILD=1 xcodebuild -scheme programa-unit -derivedDataPath /tmp/programa-w1-jsonc
-parallel-testing-enabled NO
-only-testing:programaTests/ProgramaConfigDecodingTests
-only-testing:programaTests/ProgramaConfigJSONCDecodingTests test
```
Result: TEST SUCCEEDED — 37 tests executed, 0 failures.