Sublime Forum

[Bug] ST3 Java Syntax Highlighting Breaks in method signatures

#1

More specifically, the following conditions seem to break java syntax highlighting in ST3…

  1. in-line comments in method signatures
  2. line comments in signatures
  3. parameterized annotations in java method signatures

See the examples below, (cut and paste into sublime and compare to the generated markdown below).
Note! I’m using Monokai Extended color scheme, however all the default color schemes I looked at have the same issues.


class Foo {

    // Broken! (in-line comment)
    public Foo(final String arg1 /*, final int arg2*/ ) {
        // ...  logic 
    }

    // Broken! (line comment)
    public Foo(final String arg1
        // the next line is commented out because we don't want to use it yet.
        // final int arg2
      ) {
        // ...  logic 
    }
}

  • the in-line comment highlights as though it is code, not a comment

  • the whole whole line text comment is the wrong color

  • the final int arg2 line is highlighted as though it is code, not a comment

  • Other ramifications… The closing braces and parrens are not calculated correctly if a comment contains any. For example change the line comment containing final int arg2 to final int arg2 ) {. This can cause issues with plugins like MarkdownExtended which does not think the the code block closed and then incorrectly highlights the rest of the page like though it were java. This may actually be an issue with markdown extended, but it is likely related to the internal highlighting, regardless.


class Foo {
    // OKAY! (annotated, not parametrized)
    public Foo(@Nullable final String arg1) {
        // ...  logic 
    }

    // BROKEN! (parameterized annotations, added comments also )
    public Foo(
            /* comment for property; broken with wrong highlighted color */
            // also broken
            @JsonProperty("something") final String arg1,
            /* ;comment for property broken no highlighting at all */
            // ;broken comment
            @JsonProperty("Test 2") final int arg2
            ) {
        // ...  logic 
    }
}

  • the second method’s first argument:
    • the annotation argument "something" is not higlighted like a String
    • the class String no longer has highlighting
    • the method argument arg1 also has no highlighting.
  • the second method’s second argument:
    • now the annotation @JsonProperty is a different color
    • the annotation argument "Test 2" has a different annotation entirely it has the same String arg1 highlighinting in the okay example in the first consturctor.
    • similarly int and arg2 are void of highlighting.
  • adding semi colons within comments can cause subsequent comments to render correctly, but does not fix everything.
0 Likes

#2

looks like most of this has been fixed by https://github.com/sublimehq/Packages/pull/727 and will be shipped with the next build of ST.

You can follow the instructions in the readme of that repo if you want to test the changes yourself before then.

1 Like

#3

With Build 3126 being the latest currently, compare:

0 Likes

#4

Thanks for this. I downloaded and installed the lastest version. While it improves some things it breaks others, because of the introduction of additional inconsistencies I’m not sure this is progress…

  • class-level annotations have no highlighting
  • full package annotations on class members breaks accessor highlighting
  • @ on annotations in method signatures are inconsistently highlighted
  • annotations in methods signatures without parameters break final highlighting
  • parameter names in method signatures are inconsistently highlighted
  • method return class highlighting is broken

Example (yes, this code is nonsense- only for illustration :)) :


package;
// class level annotations no longer have highlighting:
@lombok.Getter 
@lombok.EqualsAndHashCode(callSuper=true)
public class Example {

    @Nullable public String member; // OKAY
    private String member; // OKAY
    @lombok.Setter private static String member; // 'private' NOT highlighted
    @lombok.Setter protected static String member; // 'protected' NOT highlighted
    @lombok.Setter public static final String member; // 'public' NOT highlighted

    public Example(
        @Nullable final String member,  // @ sign NOT highlighted, final NOT highlighted, 
        @JsonProperty("member2") final String member, // @ sign NOT highlighted, final highlighted, member NOT highlighted
        @JsonProperty("member2") final String member,  // @ sign highlighted, final highlighted, member NOT highlighted 
        ) {
      // ...
    }

    // ReturnClass highlighting broken
    public static ReturnClass method(final String a) {

    }
    // returnClass highlighting broken
    public returnClass method(final String a) {

    }
}

0 Likes