eclipse-jdtls / eclipse-jdt-core-incubator

Eclipse Public License 2.0
8 stars 1 forks source link

Constructor completion #892

Open datho7561 opened 4 days ago

datho7561 commented 4 days ago

eg.

public class Main {
  public static void main (String... args) {
    List<String> myList = new |
  }
}

should complete, for example, ArrayList<String>() or List<String> { ... }.

Also:

public class Main {
  public static void main (String... args) {
    new |
  }
}

Should suggest possible constructors. The JDT behaviour seems to only suggest local types in this case for performance reasons.

Possible roadblock: currently, the AST returned after conversion seems to turn List<String> myList = new into List<String> myList; instead of preserving the new by doing something like List<String> myList = new $missing$().

mickaelistria commented 4 days ago

Possible roadblock: currently, the AST returned after conversion seems to turn List myList = new into List myList; instead of preserving the new by doing something like List myList = new $missing$().

What about the Tree returned by Javac? Is there some useful info we lose in translation?

datho7561 commented 4 days ago

Yes, the info is in the javac AST. Currently, we are explicitly preventing it from being added into the translated JDT AST. I have a work in progress PR that removes this and gets constructor completion (sort of) working, however this will probably cause some of the AST conversion tests to regress.

mickaelistria commented 4 days ago

I hope that if we guard the creation of the node with a check whether recovery is enabled, we can keep both completion and tests happy.