Skip to content

Fix multiline ERB comment parsing - #4182

Draft
Pybsama wants to merge 1 commit into
Shopify:mainfrom
Pybsama:codex/fix-multiline-erb-comments
Draft

Fix multiline ERB comment parsing#4182
Pybsama wants to merge 1 commit into
Shopify:mainfrom
Pybsama:codex/fix-multiline-erb-comments

Conversation

@Pybsama

@Pybsama Pybsama commented Jul 30, 2026

Copy link
Copy Markdown

Motivation

Closes #4181.

Multiline <%# ... %> comments currently leak every line after the first into
the virtual Ruby source. Prism can then parse prose as method calls, which
produces incorrect semantic highlighting and can affect other features that use
the ERB AST.

Implementation

  • Recognize the # marker when opening an ERB tag and track an explicit ERB
    comment state.
  • Replace comment content with equal-length spaces in both virtual sources while
    preserving LF and CRLF sequences and source offsets.
  • Clear the comment state on both %> and -%> closing paths, then resume
    normal host-language and Ruby scanning.
  • Ignore apparent <% openers inside an active ERB comment.

Automated Tests

Added document-level regression tests for:

  • multiline comments with LF and -%>, followed by real Ruby;
  • multiline comments with CRLF and %>, followed by both HTML and real Ruby;
  • exact virtual-source masking, newline preservation, syntax validity, and
    scanner recovery after each closing form.

Validation performed locally:

  • bin/test test/erb_document_test.rb
  • bundle exec rake
  • bundle exec rubocop
  • bundle exec srb tc
  • bin/tapioca check-shims

Manual Tests

I did not run a VS Code UI test. To verify manually, open an ERB document with
semantic highlighting enabled, add a multiline <%# ... %> block followed by
HTML and <%= ruby_code %>, and confirm that the comment remains entirely
comment-colored while highlighting resumes for the following content.

@Pybsama

Pybsama commented Aug 31, 2026

Copy link
Copy Markdown
Author

Revalidated this patch against current main (2057d0b1) on 2026-08-31:

  • Regression test first fails on unmodified current main: 11 runs, 27 assertions, 2 failures. With this patch: 11 runs, 29 assertions, 0 failures.
  • bundle exec srb tc, bin/tapioca check-shims, and bundle exec rubocop pass.
  • Full bundle exec rake passes: indexer 318 runs / 1,650,408 assertions; main suite 18,543 runs / 59,691 assertions; 0 failures, 0 errors, 14 skips.
  • The focused ERB document test passed 50 consecutive runs.
  • Semgrep ran 44 Ruby rules over the changed files with 0 findings.
  • The patch merges cleanly with current main; the rebased validation commit produces the same stable patch ID and merge tree as the existing PR patch.

I am keeping the PR as a draft because the contributor CLA requires the contributor's own legal attestation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-line <%# %> ERB comments are parsed as Ruby, so semantic highlighting colors the prose as method calls

1 participant