atom / language-csharp

C# language support for Atom
Other
62 stars 53 forks source link

Incorrect syntax highlighting for comments behind class definition #89

Closed ssrmm closed 7 years ago

ssrmm commented 7 years ago

Prerequisites

I'm not actually using Aton, but rather found this issue through the Github syntax highlighter, which directed me here. As such some of the below doesn't quiet apply to my case and I've only done the points that seemed reasonable to me and removed the other ones from the list

Description

Comments are not highlighted correctly when they start behind the first line of a class definition that implements an interface.

Steps to Reproduce

  1. Copy paste this code
    public class Test : ITest // Incorrectly highlighted
    {}
    public class Test2 // Correctly highlighted
    {}

    2 Check syntax highlighting

Expected behavior: The comment on the first line should be highlighted in grey.

Actual behavior: grafik

Reproduces how often: Always

Versions

Not using Atom at all (see Prequisities). Happens on Github issues.

tomchkk commented 7 years ago

I fixed this issue in my own implementation of the grammar by adding an include #comments in the type-declaration pattern:

Before:

      {
        begin: ":"
        end: "(?={|where)"
        patterns: [
          {
            include: "#type"
          }
          {
            match: "([\\w<>]+)\\s*"
            captures:
              "1":
                name: "storage.type.cs"
          }
        ]
      }

After:

      {
        begin: ":"
        end: "(?={|where)"
        patterns: [
          {
            include: "#type"
          }
          {
            match: "([\\w<>]+)\\s*"
            captures:
              "1":
                name: "storage.type.cs"
          }
          {
            include: "#comments"
          }
        ]
      }

I haven't got time to do my own pull request right now. Will do when I get a chance, if no one picks it up before.

damieng commented 7 years ago

Thanks @tomchkk - While testing your change I also noticed another place. Comments can technically appear anywhere and that really messes up the grammar system as it's based on pattern matching using regexes rather than a traditional parser structure so we might not be able to support them everywhere - thankfully in these two cases it works just fine :)