atom / language-ruby

Ruby package for Atom
Other
101 stars 144 forks source link

Some kinds of ERB commenting break highlighting #263

Closed csuhta closed 5 years ago

csuhta commented 5 years ago

Prerequisites

Description

Certain kinds of ERB commenting will break the syntax highlighting flow, such as <% # comment %> and <%-# comment %>

Steps to Reproduce

A poorly colorized file shown below:

<%# This is a ERB comment %>
<%= @object.variable %>

<%-# This is also a ERB comment %> <!-- Styles broken past this point --->
<%= @object.variable %>

<%# This is a comment ERB %>
<%= @object.variable %>

<% # This is a comment %> <!-- Styles broken past this point --->
<%= @object.variable %> 
q0rwisizvd 3kcntrvorq

Expected behavior: Syntax highlighting handles the comment

Actual behavior: Syntax highlighting breaks down for future Ruby blocks after the comment

Edit by @rsese to add screenshot

erb-comment-highlighting

Reproduces how often: Always

Versions

Edit by @rsese: also reproduced with 1.37.0-nightly12 on macOS 10.12.

❯❯ apm --version
apm  2.1.2
npm  6.2.0
node 8.9.3 x64
atom 1.33.1
python 2.7.15
git 2.20.1

❯❯ atom --version
Atom    : 1.33.1
Electron: 2.0.16
Chrome  : 61.0.3163.100
Node    : 8.9.3
rsese commented 5 years ago

Thanks for the report! Reproduced with 1.37.0-nightly12 on macOS 10.12.6.

erb-comment-highlighting

dreamalligator commented 5 years ago

confirmed that this is a tree-sitter issue, so I turned this back off and no longer a zillion errors:

image

> apm --version
apm  2.1.3
npm  6.2.0
node 8.9.3 x64
atom 1.36.0-beta1
python 2.7.15+
git 2.19.1

> atom --version
Atom    : 1.36.0-beta1
Electron: 2.0.18
Chrome  : 61.0.3163.100
Node    : 8.9.3

> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:    18.10
Codename:   cosmic
jasonrudolph commented 5 years ago

Actual behavior: Syntax highlighting breaks down for future Ruby blocks after the comment

☝️ This is a nice summary of the issue. Thanks, @csuhta.

@maxbrunsfeld and I looked into this issue yesterday. Building on the summary above, the syntax highlighting works correctly when using an ERB-style comment (i.e., <%#), but it breaks when using an ERB statement that includes a Ruby-style comment (i.e., a <%, <%-, or <%= node that contains a Ruby comment ):

Screen Shot 2019-05-03 at 9 48 36 AM

We found that this issue also exists for EJS:

Screen Shot 2019-05-03 at 9 55 15 AM

It seems like fixing this issue is going to be a rather substantial undertaking, so I don't yet know when we'll be able to address this issue. In the meantime, if you're able to use ERB-style comments exclusively (which I know won't be a viable solution for everyone), then you can work around this bug.

We'll likely open an issue with additional details from our findings, since the underlying issue goes beyond language-ruby and ERB.

jasonrudolph commented 5 years ago

tl;dr: https://github.com/atom/atom/pull/19291 resolves the most common cases where this issue crops us, and the fix is targeted for inclusion in Atom 1.38. 😅

Before and After

Ruby comments

Before

Screen Shot 2019-05-09 at 10 05 03 AM

After

Screen Shot 2019-05-09 at 10 05 06 AM

ERB comments

Before

Screen Shot 2019-05-09 at 10 04 33 AM

After

Screen Shot 2019-05-09 at 10 07 00 AM

Remaining edge case and available workarounds

In the fairly uncommon case where you have a Ruby comment in an ERB directive followed by additional ERB directives on the same line, the latter ERB directives are currently styled incorrectly:

Screen Shot 2019-05-09 at 10 27 14 AM

We're tracking this bug in https://github.com/tree-sitter/tree-sitter/issues/327. As seen in the screenshot above, there are two workarounds for this bug in the meantime:

Because the problem identified in the issue body above is now resolved, and because we're tracking the remaining edge case in a separate issue, I'm going to close this issue out.

Thanks again for reporting this, @csuhta. :bow: