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?
e.g.
I have this function:
def foo(a:Int, b: String, c: Long) {???}
when I type:
fo<ctrl+space>
I'd end up with
foo($cursor$)
at this point it would be nice to have an intention "add all named arguments"
which if selected would produce this:
foo(a=,b=,c=)
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
Please sign in to leave a comment.
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.
Attachment(s):
parameter info.jpg
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.
This really improves readability of the code. Feature requested! 👍
+1, would be a huge time-saver!
+1 yes, please add this feature.
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."
Any update on this from Jetbrains? I would like this feature as well.
+100000
Named args are a de-facto best practice, and it would help a lot to have a method call pre-filled with e.g.:
```
myFunc(id = , numerator = , denomenator = )
```
Use This plugin:
https://plugins.jetbrains.com/plugin/10942-kotlin-fill-class
Nice Plugin!
too bad it isnt compatible with current versions
There is a new plugin, kotlin-function-arguments-helper (https://plugins.jetbrains.com/plugin/14168-kotlin-function-arguments-helper) that does this and is more compatible.
It's still not nearly as good as it could be -- I really want the tab-through-arguments behavior.
I get the sense that the JetBrains folks don't use named arguments nearly as much as some of us do. I use them constantly, basically any method with more than one argument. I think it makes code much more readable. I also put each argument on it's own line, which helps a lot with that.
Is there any plugin or other way to add these names in bulk? i.e. if I wanted all callers of and methods in a package to get the named parameters added?
Was googling to see if JetBrains finally gave us a way to do the “add names to call arguments” globally (I want to do this at the entire codebase level). Seems like they haven't.
Came across this thread and the question above, about wanting to do it in bulk same as me.
Best I've come across is this plugin: https://plugins.jetbrains.com/plugin/18248-kotlin-bulk-add-name-params
But for real, I really wish JetBrains had this natively. This plugin, while the best I've found, only lets me run it file by file. I want to run it globally on the entire codebase.
+1
Hi, is there an update on this feature? I do data science using Pycharms+Python and named features are very common in my workflow, this would be very helpful! Thank you.
+1
Please implement this feature! It would be a massive time saver!
Meantime, I came up with a workaround: define the function/constructor call with just nulls (as many as necessary), example
foo(null, null, null)
, then Option + Enter > Add names to call arguments.