Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix IntelliJ IDEA method parameter auto-completion?

I am using IntelliJ IDEA 15, and I noticed that (by default) Eclipse offers a much more convenient auto-completion, when it comes to writing method calls, which require multiple parameters.

Eclipse automatically fills in default parameters and allows you to quickly navigate through them by pressing Tab:

enter image description here

However, IntelliJ IDEA does not handle it as conveniently and makes you write them manually:

enter image description here

Is there a way to make IntelliJ IDEA, handle method call auto-completion in a similar way to Eclipse's, and pre-write all the parameters for you, having you just press Tab (or another key) to navigate through them? If it is not possible in original IntelliJ, is there an add-on/plugin/external tool that will improve the intelligent code completion in such cases?


Note: I am not being lazy, it just gets quite annoying, having to manually complete each parameter and put a comma after each one, when code completion should do it for you.

like image 228
Victor2748 Avatar asked Feb 16 '16 02:02

Victor2748


People also ask

How do I enable auto completion in IntelliJ?

By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.

Why Autocomplete is not working in IntelliJ?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.


2 Answers

IntelliJ doesn't do it and AFAIK there isn't a plugin for it.
There is no solution for you (unless you built a plugin yourself, but then you'd just have another job to maintain that plugin)

The alternative is to break the habit/need for it and use IntelliJ's Code Completion shortcuts:

  • Ctrl+P to view possible parameters for function.
  • Ctrl+Shift+Space to list the possible variables that could be entered as a parameter in the respective parameter position (based on type).
    This also enters a comma if another parameter is required for the function.

Hardcoding numbers/strings as parameters to a custom function wouldn't be advisable as that negates the point of the parameters. It's better practice and more common to pass in a pre-defined variable; At which point Ctrl+Shift+Space is the easiest way for Code Completion.
This would also prevent you from closing quotations and adding commas.

Also note: IntelliSense is Microsoft's Intelligent Code Completion implementation which neither IntelliJ nor Eclipse uses.


As frant.hartm states in their answer:

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

They even state that people are welcome to make a plugin that does this.

like image 192
Harmelodic Avatar answered Sep 18 '22 08:09

Harmelodic


The closest thing to this AFAIK is "method parameter completion", which allows you to auto complete parameters of current method as parameters of the inner method call at once (works for methods and constructors when calling super()).

method parameter completion

Unfortunately the view of Intellij developers is that this feature would be too error prone. See this issue on youtrack.

like image 22
František Hartman Avatar answered Sep 20 '22 08:09

František Hartman