Is there a feature to automatically add in named parameters for new functions?

I saw that there was an intention to 'use named arguments for current and all subsequent arguments'

is there any way to have the plugin automatically generate these for a new method?


I have this function:

def foo(a:Int, b: String, c: Long) {???}

when I type:


I'd end up with

at this point it would be nice to have an intention "add all named arguments"
which if selected would produce this:


and then cursor would jump from a to b to c just like in a live template so that they can be quickly filled in

Comment actions Permalink

Hi, Benjamin,
There is no such action. Do you often use named arguments? If so, can you describe your usage scenarios?

If you just want to check signature of a method, you can use "Parameter Info" feature (Ctrl + P). It shows names, types and default values of parameters. It is also handy if there are overloaded alternatives.

parameter info.jpg
Comment actions Permalink

Yeah, I use named parameters quite frequently, basically whenever the order of arguments to a method don't have a natural, well known order, and the types are primitives.

In this case named parameters makes the code more readable at the call site, and guarantees that if someone changes order at the declaration site, the call site isn't affected.

So my workflow ends up writing the method name, using that to jump to the declaration, selecting the parameters, copy them, going back to the call site, pasting them, erasing the types, adding a bunch of '=' and then filling the method while the IDE blast a bunch of red-squiggly lines at me.

edit: Yep thanks for the suggesting of ctrl+p, but unfortunately, when you have a method that has several parameters, helpful as ctrl+p is to put them in the right order, it's a lot of rote typing to get the names all filled in.

edit2: perhaps a better workflow would be to use ctrl+p to just put them in the right order initially then use the intention to add the names after I do that.

Comment actions Permalink

This really improves readability of the code. Feature requested! 👍

Comment actions Permalink

+1, would be a huge time-saver!

Comment actions Permalink

+1 yes, please add this feature.  

Comment actions Permalink

There is an intention called "Add names to call arguments", but for some reason it is not always available.

edit: The intention is not always available because "named arguments are not allowed for non-Kotlin functions."

Comment actions Permalink

Any update on this from Jetbrains? I would like this feature as well.


Please sign in to leave a comment.