10

Do Eclipse have a plugin for type ahead autocompletion like Visual Studio, so I don't have to destroy my spacebar by pressing Ctrl+Space all the time? (If you don't know how it works in Visual Studio, please don't bother answering.)

And also, can I limit the autocomplete to imported packages, rather than every single Java class on earth? It's fustrating seeing suggestions from awt and swing etc., when I'm working with GWT. And I don't want to add every single Java class to the filter, that's just stupid. (Again, like how it's done in Visual Studio!)

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
  • @Claus, you could add the `visual-studio` tag, to attract more visual-studio *and* eclipse savvy users who could provide a better answer than mine. – VonC Jan 02 '10 at 11:01
  • 2
    @Claus, if you don't want to listen to Eclipse-savvy users, you will miss out on lots of nifty features in Eclipse. Be open-minded instead. – JesperE Jan 02 '10 at 11:35
  • 2
    How is requesting extremly useful features that other IDEs have, being closed-minded? "features" that requires me to spend longer type developing, and slowing down my IDE, isn't nifty. – Claus Jørgensen Jan 02 '10 at 12:13
  • 1
    No, but **other** features that Eclipse-users might suggest might be nifty. How would you know if you don't want to listen to them? – JesperE Jan 02 '10 at 12:37
  • 1
    If you would take the time to **explain** the feature instead of blankly dismissing everyone who doesn't know what you are talking about, you might get better answers. – JesperE Jan 02 '10 at 12:39
  • I requested people who used both Visual Studio (.NET) and Eclipse to answer. If people don't know about this, they should go download Visual Studio Express, and be more familiar with the IDE, so they can see what features other IDEs have. – Claus Jørgensen Jan 02 '10 at 12:53
  • Just edited my answer with an illustration of the difference of auto-completion approaches between VS and Eclipse. – VonC Jan 02 '10 at 13:32
  • Good visual intro on Eclipse code completion here: http://showmedo.com/videotutorials/video?fromSeriesID=6&index=1&name=IntroductionToEclipseWithJava2_JohnM . The CTRL+Space on an empty line to quickly override a super method actually was kind of new to me! – VonC Jan 02 '10 at 19:11
  • @Claus Remember Eclipse auto-imports for you when it autocompletes. If you start with an empty class and you want Eclipse typeahead to only autocomplete from imported packages for you, then by definition, autocomplete will never work (unless it autocompletes for classes in the same package as your current class). – hashable Feb 10 '10 at 19:23

4 Answers4

24

Regarding your second part, yes you can

  • Open Eclipse
  • Select Window/Preferences from the menu
  • Expand Java/Appearance/Type Filters from the menu on the left
  • Click the "Add package" button, enter "java.awt" (without the quotes) and click OK
  • OK your way out

This will make Eclipse remove any matching classes from the java.awt package from your type ahead list. Very nice...

So "type-ahead" exists in Eclipse (mentioned in this status report in June 2006), but is synonym of auto-completion, most often triggered by CTRL+ Space... (which is not exactly what you are looking for)


To be more specific, the kind of automatic auto-completion (completion while you are typing, with a "Common" or "All" list of possible completions) you have in Visual Studio is not there in Eclipse (actually read below):

alt text

Original answer January 2010:

At least, not without a dedicating plugin.
And even with that plugin, it would have to follow a TemplateCompletionProcessor, meaning it would need a list of characters triggering said completion (again, not what you are looking for), by redefining method getCompletionProposalAutoActivationCharacters().

Update November 2011:

Cristi mentions in his answer (upvoted) a great workaround, which consists adding all the letters as Auto activation triggers for java.
See also "Automatically opening completion window in Eclipse".

From the thread "Eclipse auto-completion ":

Windows -> Preferences -> Java -> Editor -> Content Assist
  • Set delay to: 0 (actually >0 is better: 50, it avoids CPU picks because of constant listening)
  • Set triggers to:
    .(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ@

content assist options

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I know that, and I wrote as part of the question that I didn't want to do this, as it's ridiculous stupid to add all classes in Java to the filter! – Claus Jørgensen Jan 02 '10 at 10:47
  • 1
    @Claus: even if you can enter packages instead? Anyhow, I am not aware of other "auto-completion" mechanisms. – VonC Jan 02 '10 at 10:49
  • 1
    As I wrote, I want to only show the imported packages, not filter out everything I don't need. – Claus Jørgensen Jan 02 '10 at 10:53
  • Other relevant links on the eclipse side: http://wiki.eclipse.org/FAQ_How_do_I_add_Content_Assist_to_my_editor%3F and http://wiki.eclipse.org/FAQ_How_can_Content_Assist_make_me_the_fastest_coder_ever%3F – VonC Jan 02 '10 at 20:23
15

My answer may come too late, but maybe will help others searching this feature in eclipse. This workaround works for me (eclipse helios):

Go to Windows -> Preferences -> Java -> Editor -> Content Assist. Here, enable Auto activation and set Auto activation delay to a low value, let's say 50 ms. Then comes the workaround: In Auto activation triggers for java, simply put all the characters: abcdefghijklmnopqrstuvwxyz.

And there you go, just type something.

sth
  • 222,467
  • 53
  • 283
  • 367
Cristi
  • 151
  • 1
  • 3
2

Completion is triggered when pressing ".", if that is what you are referring to as "type-ahead autocompletion". This is what Visual Studio also does, unless you are referring to another Visual Studio feature I'm unaware of.

Limiting completion to only imported packages I think is a somewhat unorthodox thing to do; you are forced to rely on wildcard imports to define the set of types to complete on. I think most users would consider that less than useful. You're welcome to elaborate on your use case for this, though. For example, why would you want to exclude all Java classes from completion?

BTW, using "type filters" (as VonC suggests) doesn't require you to add every single class. I typically (globally) exclude java.awt.*, sun.com.*, org.omd.*, and a few others. Eclipse also sorts completion according to a (type-sensitive) heuristic which usually results in the most relevant types being displayed at the top. For example, auto-completion inside a method call will put the variables which matches the method type signature at the top.

JesperE
  • 63,317
  • 21
  • 138
  • 197
  • I don't have access to any .NET-enabled VS at the moment to try, but how are the completions displayed? A drop-down menu like the one triggered on "." seems a bit invasive. – JesperE Jan 02 '10 at 12:54
  • @Claus, I find it invasive, because sometimes I want to type the name of a method that I haven't written yet but am planning to write in a few minutes. It's very confusing when VS "corrects" my spelling by substituting the name of a class from the framework. – finnw Jan 15 '10 at 19:11
  • Oh, interesting -- you can add wild cards -- that's *sort of* better. – BrainSlugs83 Apr 18 '15 at 19:15
  • @finnw -- Visual Studio doesn't do it that way -- you have to press Enter or Tab to trigger the auto completion insert -- it doesn't just randomly insert crap while you type (like Eclipse does). – BrainSlugs83 Apr 18 '15 at 19:22
0

I know that Claus spoke of Java in the second part of his question, but the general question is about any language in Eclipse (no Java tag here), so the following might be of use to python eclipse coders:

Go to Windows -> Preferences -> PyDev -> Editor -> Code Completion. Here, check the box next to "Request completion on all letter chars and '_'?".

(Purposefully similar to Cristi's answer.)

Greg Kramida
  • 4,064
  • 5
  • 30
  • 46