Skip to content

support allowComments & allowTrailingCommas - #179

Merged
jdesrosiers merged 10 commits into
hyperjump-io:mainfrom
Ahmedmhmud:feat/support-allowComments
Nov 11, 2026
Merged

jdesrosiers merged 10 commits into
hyperjump-io:mainfrom
Ahmedmhmud:feat/support-allowComments

Conversation

@Ahmedmhmud

Copy link
Copy Markdown
Contributor

Added support for allowComments and allowTrailingCommas.

Comments and trailing commas are now collected by the parser and reported by JsoncDiagnosticsProvider instead of as syntax errors. By default, they're errors in .json files and ignored/warnings in .jsonc files. Setting allowComments: true or allowTrailingCommas: true in the schema suppresses them, while false does not override the defaults. Works through $ref and allOf.

Closes #169

Ahmedmhmud and others added 3 commits November 3, 2026 01:00
Use the annotations getAnnotations returns instead of rebuilding them,
merge the duplicate trailing comma loops, and type the diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the root schema and the subschemas it always applies (allOf, $ref)
can allow comments or trailing commas, and any of them setting true is
enough. Conditional subschemas (anyOf, oneOf, if/then/else) are ignored
even when they match. A comma with no value before it is still an error
when trailing commas are allowed.

These tests fail until the provider and parser are updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I pushed two commits: a cleanup of the provider and seven tests that fail until the two issues below are fixed.

To match vscode, only the root schema and the subschemas it always applies (allOf, $ref) should be counted. anyOf, oneOf and if/then/else are ignored even when they match. If the keyword is applied multiple times, any true enables the rule.

[,] and {,} should be considered missing values, not trailing commas, so allowTrailingCommas shouldn't hide them. parseComma should report value-expected. The two "comma-only" tests in parse.test.ts will need updating.

@Ahmedmhmud

Ahmedmhmud commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Great catches @jdesrosiers !
Both are fixed. The resolution problem was that annotations from keywords (anyOf, oneOf, if/then/else) were being counted, now only (root, allOf, $ref) are used via getLocationAnnotations(), and some() makes any true win.
The parsing problem was check order a comma with no value before it, now reports value-expected instead of being recorded as a trailing comma.

The CI failed on macos and it's a timeout, Could you re-run this one please?

jdesrosiers and others added 6 commits November 11, 2026 11:28
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser no longer reports trailing-comma or comment-not-allowed, so the
JSONC provider looks up its messages directly instead of building fake
syntax errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Annotation accessors return plain booleans, and the schema isn't validated
when there are no comments or trailing commas to report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes! I pushed a few cleanup commits:

  • Removed a duplicate unclosed-comment test and renamed the comma-only tests to say "on the bracket", which is where the error is reported.
  • skipComment now goes through reportScanError, so unclosed comments are handled in one place.
  • Added a named Span type for comments and trailing commas.
  • Moved the trailing-comma and comment-not-allowed messages out of the parser's SyntaxErrorCode. The parser no longer produces them, so the provider uses a new Localization.getMessage() instead of building fake syntax errors.
  • allowComments() and allowTrailingCommas() now return plain booleans. The provider also skips schema validation when there are no comments or trailing commas to report.
  • Added support for VS Code's deprecated allowsTrailingCommas spelling.

I need to correct my last review. I said "any true enables the rule" matches VS Code, but it doesn't. VS Code uses the first boolean it finds: the root first, then allOf in order, with a $ref'd schema taking precedence over its siblings. We're keeping "any true wins" anyway, because matching VS Code would need annotations in order. The current implementation and tests are what we want.

@jdesrosiers
jdesrosiers merged commit b0dd375 into hyperjump-io:main Nov 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support allowComments VScode's custom keyword

2 participants