eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

Smart autocomplete for types

Open alexwaeseperlman opened this issue 7 years ago • 9 comments

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.

alexwaeseperlman avatar May 20 '17 17:05 alexwaeseperlman

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 ;-)

fbricon avatar May 20 '17 21:05 fbricon

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?

alexwaeseperlman avatar May 20 '17 23:05 alexwaeseperlman

what do you mean?

fbricon avatar May 21 '17 03:05 fbricon

peek 2017-05-21 09-54

alexwaeseperlman avatar May 21 '17 13:05 alexwaeseperlman

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

fbricon avatar May 21 '17 14:05 fbricon

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

alexwaeseperlman avatar May 21 '17 14:05 alexwaeseperlman

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

fbricon avatar May 21 '17 15:05 fbricon

Dears,

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

this is really a very handy feature.

xqliu avatar Mar 13 '19 10:03 xqliu

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:

  • boolean add(E e)
  • void add(int index, E element)

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.

jdneo avatar Jul 19 '22 06:07 jdneo