From ad8ed8bc1329a61e739b6aaf5151f74904f8e481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sat, 2 Aug 2025 11:41:07 +0200 Subject: [PATCH 1/2] Trim trailing commas from semantic tokens output to ensure valid JSON --- analysis/src/SemanticTokens.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/analysis/src/SemanticTokens.ml b/analysis/src/SemanticTokens.ml index 58564aa1f..4683f9eab 100644 --- a/analysis/src/SemanticTokens.ml +++ b/analysis/src/SemanticTokens.ml @@ -79,6 +79,11 @@ module Token = struct ^ string_of_int length ^ "," ^ tokenTypeToString type_ ^ "," ^ tokenModifiersString) + let remove_trailing_comma buffer = + let len = Buffer.length buffer in + if len > 0 && Buffer.nth buffer (len - 1) = ',' then + Buffer.truncate buffer (len - 1) + let emit e = let sortedTokens = e.tokens @@ -87,6 +92,10 @@ module Token = struct in let buf = Buffer.create 1 in sortedTokens |> List.iter (fun t -> e |> emitToken buf t); + + (* Valid JSON arrays cannot have trailing commas *) + remove_trailing_comma buf; + Buffer.contents buf end From 41483960c894b438af7f16a2c88d71deb6f7b33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sat, 2 Aug 2025 11:44:40 +0200 Subject: [PATCH 2/2] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4feeb29e9..876eebbff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ #### :bug: Bug fix +- Fix: `rescript-editor-analysis.exe semanticTokens` sometimes returned invalid JSON, which affected syntax highlighting. https://github.com/rescript-lang/rescript-vscode/pull/1113 + - Fix: hang in `rescript-editor-analysis.exe codeAction` that sometimes prevented ReScript files from being saved in VS Code. https://github.com/rescript-lang/rescript-vscode/pull/1112 - Fix: show existing compiler errors and warnings on file open. https://github.com/rescript-lang/rescript-vscode/pull/1103