jskinner / DefaultPackages

Old bug tracker for Sublime Text's "Default Packages", e.g. bad syntax highlighting
http://web.archive.org/web/20150524043750/https://www.sublimetext.com/forum/viewtopic.php?f=2&t=12095
26 stars 2 forks source link

Java 8 method references before keyword names not supported (breaks symbol matching) #140

Closed FichteFoll closed 8 years ago

FichteFoll commented 9 years ago
import java.util.*;
import java.util.stream.*;

/*
Lines entered so screenshot
can show the list of methods
*/

public class SyntaxTest {
   public static void main(String... args) {
      printList(Arrays.stream(args)
         .collect(Collectors.toCollection(ArrayList::new)));
      anotherMethod();
   }

   private static void printList(List<String> args) {
      args.stream().forEach(System.out::println);
   }

   private static void anotherMethod() {

   }
}

System.out::println seems to not be an issue, but ArrayList::new is, seemingly because "new" is also a keyword.

Okay: o

Broken: b

Mirror from http://www.sublimetext.com/forum/viewtopic.php?f=3&t=18921

StrangeNoises commented 9 years ago

I have a fix, but I don't seem to be able to apply it in Sublime Text in a way that it'll take notice.

ST3 actually gets its Java language grammar and highlighting from the Textmate Java bundle. I was able to fix the issue there with a regex change in the Syntaxes/Java.plist file.

In the anonymous-classes-and-new section, edit the begin regex

from:

begin = '\bnew\b';

to

begin = '\b(?<!::)new\b';

Which makes it ignore the new keyword when it's prefixed by two colons. This appears to fix it for me in TextMate if I make the change in the Bundle Editor but I don't seem to have the knack of applying a fixed bundle myself. As TextMate isn't my main editor, I don't propose to work hard at finding out why. No, I think I just have found out why; it's an XML file, I needed to entityise the < in the regex!

The equivalent file in ST3 is: Packages/Java/Java.tmLanguage. However, making that same change (and entityising the < this time!) is being simply ignored. I deleted the cache files but I note the Java.tmLanguage.cache and .rcache files aren't being recreated. There's presumably something I've done to offend it but I can't see it, the change is just being silently ignored. There is a Java.sublime-syntax.cache and .rcache file pair, but I can't see any Java.sublime-syntax original anywhere. So if those are being generated out of the .tmLanguage file, I don't know why it's ignoring the change that works in Textmate.

I'm pretty sure this is the fix though, it's just how to apply fixes, both to this and the TextMate bundles system that seems to be unnecessarily difficult.

EDIT: TextMate Issue here: https://github.com/textmate/java.tmbundle/issues/37

EDIT: Fixed for me by moving my changed Java.tmLanguage file into Packages/User where it probably always should have been! :-} And it works.

FichteFoll commented 9 years ago

@StrangeNoises, you can also file a pull request now to the official repository of ST's shipped packages: https://github.com/sublimehq/Packages

Note the new format however.

StrangeNoises commented 9 years ago

Yes I did just note the new format, now there is a Java.sublime-syntax instead. But I was able to make the same change in the equivalent place there, and it's working for me. Expect a PR soon (just got to check that procedure that I do it right...)

StrangeNoises commented 9 years ago

... and done: https://github.com/sublimehq/Packages/pull/89

jrappen commented 8 years ago

@FichteFoll I believe you can close this now.