eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 392 forks source link

Smart autocomplete for types #232

Open alexwaeseperlman opened 7 years ago

alexwaeseperlman commented 7 years ago

As stated in this article about IDEA vs Eclipse, IDEA will only show autocomplete options based on context.

List<String> result= new ArrayList<>(5);
result.add(Integer. // ctrl-space

In this situation, it would wonderful if it only showed me the results that return strings. Instead, it shows me all of the constants at the top and I have to scroll to see anything that returns a string.

I doubt this would be very hard to implement because I assume it would just be a single if statement somewhere. It's possible I should be giving this issue directly to eclipse.jdt.core so tell me if I should move.

fbricon commented 7 years ago

If you try String s = Integer. //ctrl-space you'll see methods returning String on top.

Eg. in VS Code :

screen shot 2017-05-20 at 5 53 09 pm

So it seems to me the context is not aware of generics somehow. Please open a bug in jdt.core. Then we can ask @othomann to take a look ;-)

alexwaeseperlman commented 7 years ago

This is also probably meant for upstream (I'm not completely sure which responsibilities are handled by who) but would it be possible to autocomplete @Overrides?

fbricon commented 7 years ago

what do you mean?

alexwaeseperlman commented 7 years ago

peek 2017-05-21 09-54

fbricon commented 7 years ago

https://www.screencast.com/t/AYFxtppNr8 shows a more optimal workflow: type the name of the method you want to override, completion will add the @Override annotation and create the whole method body.

Unfortunately it is not that trivial to implement properly, as explained in #206, since we need to move some code around in upstream JDT

alexwaeseperlman commented 7 years ago

peek 2017-05-21 10-39 Doesn't work for me for some reason. Is it possible I have a conflicting package?

fbricon commented 7 years ago

The override fix is not merged (see #206) because it's incomplete. It doesn't work for anyone at the moment.

xqliu commented 5 years ago

Dears,

is there any update or something we could do to move this ticket forward?

this is really a very handy feature.

jdneo commented 2 years ago

As stated in this article about IDEA vs Eclipse, IDEA will only show autocomplete options based on context.

List<String> result= new ArrayList<>(5);
result.add(Integer. // ctrl-space

In this situation, it would wonderful if it only showed me the results that return strings. Instead, it shows me all of the constants at the top and I have to scroll to see anything that returns a string.

I doubt this would be very hard to implement because I assume it would just be a single if statement somewhere. It's possible I should be giving this issue directly to eclipse.jdt.core so tell me if I should move.

I think it's by design. Since the List#add() has two versions of signature:

In this case, String and int are all expected types.

If you try result.get(Integer. // ctrl-space, you can see int and Integer types comes first, and String goes last.