Skip to content

Trim trailing commas from semantic tokens output to ensure valid JSON #7750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 2, 2025

Conversation

mediremi
Copy link
Contributor

@mediremi mediremi commented Aug 2, 2025

In certain cases, analysis semanticTokens <file> will return an array with a trailing comma:

let make = () => {
  <span className={ />
}
{"data":[0,4,4,1,0,1,2,1,3,0,0,1,4,7,0,]}

As this is not valid JSON, the VS Code extension throws an error:

image

And syntax highlighting is affected (notice the span):

image image

I've fixed this issue by trimming the trailing comma, if present.

@mediremi mediremi marked this pull request as ready for review August 2, 2025 09:36
Copy link

pkg-pr-new bot commented Aug 2, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7750

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7750

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7750

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7750

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7750

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7750

commit: f0f27a4

@nojaf nojaf requested a review from zth August 2, 2025 11:59
@nojaf
Copy link
Member

nojaf commented Aug 2, 2025

I don't know enough about semantic tokens to review this.
Would feel more at ease if @zth could take a look.

Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

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

This looks great! Mid to long term we should probably refactor this to either a) use the same JSON stringifiers as the rest of the project, or b) introduce yojson or similar (which I believe we've talked about).

But this is good just to fix the issue. Great with the test as well!

@zth zth merged commit 81f4b2f into rescript-lang:master Aug 2, 2025
27 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.

3 participants