12

So, on Eclipse Luna, I often encounter the situation where I'm typing a method name, but the first autocomplete suggestion is not the method I am looking for but something that is prefix-equivalent but longer, as in this example:

Unhelpful autocomplete suggestions

In the example, I just wanted the element(String name) method, so instead of hitting Return, I type ( instead. The result, quite annoyingly, is this:

After accidentally triggering autocomplete

This is clearly not what I was looking for. Is there a way to prevent Eclipse from performing auto-complete when I hit open-parenthesis (()?

These are my content assist settings (aparrently, I don't have code recommenders installed at all in this eclipse installation): Content assist settings enter image description here

Jannik Jochem
  • 1,516
  • 1
  • 14
  • 28
  • It sounds like you want Eclipse to autocomplete the right thing (`element(qName)`), rather than not autocompleting at all. – Matt Ball Aug 05 '14 at 15:25
  • That would of course be preferable, but there probably isn't a setting for "always guess auto-completes correctly". In this case, I could hit down-arrow five times, but I'd rather just have a way to further restrict the set of auto-complete suggestions by typing on. If I wanted `elementIterator()`, I could do so by typing "I". For the `element(String name)` method, I don't seem to have this option. – Jannik Jochem Aug 05 '14 at 15:50
  • Switch to IntelliJ? Except, IntelliJ sometimes has similar issues. – Warren Dew Aug 09 '14 at 03:57
  • See http://stackoverflow.com/q/14297735/1700321. – Aleksandr M Aug 14 '14 at 12:15
  • Not yet. I didn't get around to trying the suggestions in the question linked by Aleksandr yet. Those look promising. – Jannik Jochem Aug 21 '14 at 08:59
  • Jannik, can you give me the full qualified name of Element - or any other situation with java.* classes where this happens to you? I'll reproduce to see what happens/causes this ordering issue (FWIW, it appears to me that you haven't CR enabled. Thus I assume this is not related to CR). – Marcel Sep 07 '14 at 06:43
  • Hi Marcel, the example above was `org.dom4j.Element`. I just tried to reproduce the situation I described - for some reason, element() is at the top of the list now. I'll let you know if I encounter the problem again. – Jannik Jochem Sep 08 '14 at 07:13
  • I just checked again. aparrently, I was testing with the wrong line. I can now reproduce the problem. I'm adding screenshots of my content assist settings to the question. I'll also send you the compilation unit in question (sorry, can't post the whole code here due to confidentiality issues). – Jannik Jochem Sep 08 '14 at 07:22
  • Its 2019 and I am still encountering this issue with Eclipse 2018-12. Seems like the obvious answer is that content assist should only autocomplete on return keyclick or mouse click. Eclipse should certainly NOT autocomplete on parenthesis keyclick. Parenthesis keyclick should mean 'accept my work' as is. – JohnC Mar 12 '19 at 18:07

5 Answers5

15

In Eclipse 4.11 (2019-03), and possibly earlier, the answer to this is under Preferences → Java → Editor → Content Assist → Disable insertion triggers except 'Enter'. After I checked that box, editing became a lot less annoying.

I have no idea why Eclipse doesn't do it by default. Who types map.put( and wants that to autocomplete to map.compute()?

Trambelus
  • 151
  • 1
  • 2
  • 4
    This works for me - thank you. Really annoying thing, and it is a bug. I see Eclipse (4.6.3) doing this much better. Once you enter "map.p" auto suggest proposes put(...) method first. – P_M Sep 11 '19 at 10:45
3

A hack for this is to change the way Eclipse sorts the proposals.

You can go to Preferences menu and then go to the section for which you want to edit sorting. Then to de Editor section and Content Assist. For example, for Java editor, it will be Preferences > Java > Editor > Content Assist.

There you will see, more or less in the middle of the window, a section called Sorting and filtering. Inside there is an option called Sort proposalswhich you can change from by relevance to alphabetically. Save an close.

With this you will get the proposals list order alphabetically and element() will be before other methods starting by element.

EDIT: Tested in Eclipse Luna running in Ubuntu 14.04 and it works. You'll still get your code completed when writing ( but it will be completed with the shorter option available in the proposals list. If you want to use another method, you can continue writing some letters and the shortest option will disapear of proposals as it doesn't match what you are writing.

Isthar
  • 433
  • 3
  • 14
  • Sorry, but this is not what I'm looking for. I explicitly don't want ( to complete code and I want to have my proposals sorted by relevance. – Jannik Jochem Aug 21 '14 at 09:00
  • I'm afraid that's not possible by now. Eclipse doesn't offer such configuration option. You can disable autocomplete as @Matthias suggested, or reorder proposals to avoid the problem, but it seems imposible to stops `(` triggering autocomplete. – Isthar Aug 21 '14 at 10:03
  • This solution will only work for specific cases in which the method you want to use comes alphabetically after the one you dont want to use and is not behind another method that is alphabetically before it. Example: When I use a hashMap and try to use the `put`-method. Before: `.put+CTRL+SPACE` --> `.putAll(m)`. After using solution: `.put+CTRL+SPACE` --> `comPUTe(key, remappingFunction)`. – hamena314 Nov 04 '16 at 10:28
2

I guess your problem is the substring matches.

Go Window->Preferences->Java->Editor>Content Assist.

In Sort proposals section uncheck Show substring matches.

I found By relevance more useful then Alphabetically. I have usually checked hidden Hide proposals not visible in the invocation target, and Hide deprecated references, too.

I hope it help.

reinhardt
  • 21
  • 1
1

The feature you're fighting with is the new "Intelligent code completion" which orders methods based on average usage count. Don't ask me where they get the data. See also here: http://www.eclipse.org/recommenders/manual/#intelligent-code-completion

To disable the feature go to the preferences page Code Recommenders|Completions and uncheck "Enable intelligent code completion".

Matthias
  • 1,296
  • 8
  • 17
  • Um, on second though maybe I misunderstood your question regarding what kind of auto completion you really want to configure or disable. But it's probably something in the are of the new code recommenders. Maybe it's really the call chain auto-completion that bothers you. – Matthias Aug 10 '14 at 16:07
  • 1
    I'm pretty sure that the offered completions are not the Code Recommenders ones, because these usually have a certainity percentage on the right of the suggestions. While I think that the suggestion is wrong, the concrete problem I'm having is a usability one: typing `(` triggers insertion of the highlighted match. This is what I want to disable, since I'm never going to get perfect auto-suggestions for everything anyway. But maybe I should ask the Code Recommenders guys about this at the next Jug Darmstadt meeting ;) – Jannik Jochem Aug 11 '14 at 17:20
0

Another issue which might negatively affect code completions appears to be 'Java Proposals (Task-Focused)'. For example, it causes map.put() to be replaced with map.compute().

You can disable these from Preferences | Java | Editor | Content Assist | Advanced.

See also: http://literatejava.com/eclipse/bad-auto-completions-in-eclipse/

enter image description here

Gnoupi
  • 4,715
  • 5
  • 34
  • 50
Thomas W
  • 13,940
  • 4
  • 58
  • 76