HarlemSquirrel / language-haml

Haml language grammar for GitHub's Atom IDE
MIT License
33 stars 24 forks source link

Pipes (for line continuation) break syntax highlighting #56

Closed calebmeyer closed 7 years ago

calebmeyer commented 8 years ago
screen shot 2016-04-25 at 9 42 45 am

I took this screenshot with One Dark Syntax so that we'd have a common test ground. The markup:

%span.this#works-fine
%input.uh-oh{               |
  type: 'text',             |
  name: 'oh-no',            |
  title: "what's going on?" |
}                           |
%div.not-highlighted-correctly
  %span.neither-are-children
%a.having-more-brackets{ href: "fixes it" }
%span= "See?"

%span.note {                             |
  this: 'fixes the syntax highlighting'  |
}
%div= "But it will break if you try to render it."

It appears that pipe characters break the syntax highlighting. They also are highlighted differently (under my usual syntax theme, photon syntax) sometimes. Randomly they'll be white or purple, and I can't really figure out why. Also if you have an id before the attribute braces in the anchor tag above, it doesn't fix the highlighting (everything after the # is comment colored)

ezekg commented 8 years ago

Thanks for the report. You're right, I wasn't aware that the multi-line syntax requires a trailing pipe. I usually don't use pipes, so that's why I didn't catch it. I'll get a fix out soon.

ezekg commented 8 years ago

I haven't forgotten about this, it's just proven a lot harder to fix than I initially thought. Hopefully I'll have some time this weekend to work on it a bit more.

calebmeyer commented 8 years ago

No problem. Thanks for your work!

Alhadis commented 7 years ago

This is happening because a region of embedded Ruby highlighting isn't terminating at the closing } character:

Figure 1

If you remove the trailing pipe from the line containing the closing brace, everything suddenly highlights fine:

Figure 2

This line is to blame. I've attached a patch below that fixes this. However, I don't know a single thing about Haml, so I have no idea if these changes are valid syntax or not. I'll leave it up to you.

diff --git a/grammars/ruby haml.cson b/grammars/ruby haml.cson
index d6aab60..a3db55c 100644
--- a/grammars/ruby haml.cson   
+++ b/grammars/ruby haml.cson   
@@ -18,6 +18,9 @@
     ]
   }
   {
+    'include': '#continuation'
+  }
+  {
     'match': '^(!!!)($|\\s.*)'
     'name': 'meta.prolog.haml'
     'captures':
@@ -78,14 +81,14 @@
       }
       {
         'begin': '(?<!\\#)\\{(?=.+(,|(do)|\\{|\\}|\\||(\\#.*))\\s*)'
-        'end': '\\s*\\}(?!\\s*\\,)(?!\\s*\\|)(?!\\#\\{.*\\})'
+        'end': '\\s*\\}'
         'name': 'meta.section.attributes.haml'
         'patterns': [
           {
-            'include': 'source.ruby.rails'
+            'include': '#continuation'
           }
           {
-            'include': '#continuation'
+            'include': 'source.ruby.rails'
           }
           {
             'include': '#rubyline'
@@ -147,10 +150,10 @@
         'name': 'meta.section.object.haml'
         'patterns': [
           {
-            'include': 'source.ruby.rails'
+            'include': '#continuation'
           }
           {
-            'include': '#continuation'
+            'include': 'source.ruby.rails'
           }
           {
             'include': '#rubyline'
@@ -288,7 +291,7 @@
 ]
 'repository':
   'continuation':
-    'match': '(\\|)\\s*\\n'
+    'match': '(\\|)\\s*$\\n?'
     'captures':
       '1':
         'name': 'punctuation.separator.continuation.haml'
ezekg commented 7 years ago

@Alhadis from my tests that works great. I'll cut another patch release in a minute. Appreciate the help in getting this cleaned up. 🙂

Alhadis commented 7 years ago

Actually, it might be worth waiting until another issue is fixed with comments. See here.

Alhadis commented 7 years ago

Here's an example of an affected code block:

/ HAML comment
- # ruby comment
string
= "string"
= "string" #comment
= "string #{not_comment}" # comment

Notice how #{not_comment} is being coloured like, well, a comment.

ezekg commented 7 years ago

Hmm, it renders fine in Atom. Do you know why it's rendering different on GitHub?

image

Alhadis commented 7 years ago

Thats currently what I'm waiting on GitHub staff to help with before I can properly investigate. =) The webapp we use to preview syntax highlighting is showing the same result as Atom does. This is probably due to outdated dependencies (it's using an ancient version of Linguist to generate previews), so... we'll see once the upgrade is finished.

ezekg commented 7 years ago

Gotcha! Sounds good. I'll subscribe that issue so I'll know if I need to do anything, then I can cut a new patch release for this issue once that's all figured out.

ayaankazerouni commented 7 years ago

OS: Ubuntu 16.04 Atom: 1.17.0 language-haml: 0.24.2

EDIT: This issue presented itself after updating to 0.24.2.

Hi! This seems related, but if it's not, I can create a new issue. I'm seeing syntax highlighting breaking on line continuation as well. But I'm not using the pipe character, I'm breaking to the next line after a comma, which is allowed according to the Haml docs. Removing the line break after the comma un-breaks the syntax highlighting.

Broken syntax highlighting:

screenshot from 2017-05-18 12-38-57

Un-broken syntax highlighting:

screenshot from 2017-05-18 12-39-25

ezekg commented 7 years ago

@ayaankazerouni could you try the latest patch version?

ayaankazerouni commented 7 years ago

Ok, everything looks good now. Thanks!