Skip to content

Some playground improvements - #4213

Merged
Earlopain merged 2 commits into
ruby:mainfrom
Earlopain:playground-improvements
Sep 3, 2026
Merged

Some playground improvements#4213
Earlopain merged 2 commits into
ruby:mainfrom
Earlopain:playground-improvements

Conversation

@Earlopain

@Earlopain Earlopain commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator
  • Add color to empty locations, numbers
  • Format constant type like ruby symbol
  • Fix display of string type as [Object Object]
  • Include slice for location fields
  • Add location: to node locations like in ruby inspect output

Before:
image
After:
image

Comment thread doc/playground.js Outdated
let text = `${start.line}:${start.col}-${end.line}:${end.col}`;

if (includeSlice) {
const slice = source.slice(loc.startOffset, loc.startOffset + loc.length);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So, this is not correct. slice does by character but the offsets are in bytes and I don't know how you'd handle this in javascript. It's already the same problem with offsetToLineCol but here it would be a bit more noticable I think

Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should be ok with ffeef1e, I think

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The current implementation introduces a DOM injection risk when rendering location slices and has correctness issues in location column mapping and string-wrapper detection that can break navigation/rendering.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves the Prism playground’s AST/diagnostics rendering by enhancing how locations and certain value types are displayed, aiming to better match Ruby’s inspect-style output and improve usability when navigating locations.

Changes:

  • Reuse shared TextEncoder/TextDecoder instances and switch location calculations to use UTF-8 bytes.
  • Improve AST rendering: show location: prefix, include slices for location fields, and handle Prism string wrapper objects.
  • Adjust styling for empty () locations.
File summaries
File Description
doc/playground.js Updates AST/diagnostic rendering, location formatting, and string-type display; adds shared encoder/decoder usage.
doc/playground.css Changes the color used for empty () values in the AST tree.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread doc/playground.js
Comment thread doc/playground.js
Comment thread doc/playground.js
@Earlopain
Earlopain force-pushed the playground-improvements branch 2 times, most recently from ed00ad8 to 59ead1c Compare September 3, 2026 15:07
@Earlopain
Earlopain requested a lite review from Copilot September 3, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated byte-based line/column calculation produces incorrect columns for non-ASCII text, which will misalign Monaco cursor/highlighting and displayed locations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

doc/playground.js:252

  • offsetToLineCol currently increments col per UTF-8 byte. Monaco columns (and the displayed column numbers) are based on the decoded string/UTF-16 code units, so offsets after non-ASCII characters will produce incorrect column values and misaligned highlights.
function offsetToLineCol(utf8Bytes, offset) {
  let line = 1, col = 0;
  for (let i = 0; i < offset && i < utf8Bytes.length; i++) {
    // Check for newline
    if (utf8Bytes[i] === 10) { line++; col = 0; }

doc/playground.css:272

  • Missing trailing semicolon in this declaration; the surrounding CSS uses semicolons consistently, and keeping that convention reduces the risk of mistakes when adding more properties later.
.tree-number {
  color: #098658
}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread doc/playground.css
* Add color to empty locations, numbers
* Format constant type like ruby symbol
* Fix display of string type as `[Object Object]`
* Include slice for location fields
* Add `location: ` to node locations like in ruby inspect output
Javascript strings are always utf16, TextEncoder
converts it to utf-8 bytes.
Doing it like this seems like a fine solution
@Earlopain
Earlopain force-pushed the playground-improvements branch from 59ead1c to b4a5db9 Compare September 3, 2026 15:23
@Earlopain
Earlopain merged commit 7ad52b4 into ruby:main Sep 3, 2026
101 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.

2 participants