Skip to content

Remove trailing ", " from map-style constructor call named argument proposals #490

@mauromol

Description

@mauromol

Consider the following:

package test22;
public class MyBean {
	private String foo;
	private String bar;
	public void setFoo(String foo) {
		this.foo = foo;
	}
	public void setBar(String bar) {
		this.bar = bar;
	}
}

and the following Groovy class:

package test22
class Test22 {
	public Test22() {
		def b = new MyBean(foo: 'hello', b|)
	}
}

When you invoke code assist at "|" and you choose bar:, the result is:
def b = new MyBean(foo: 'hello', bar: __, )
The trailing comma automatically inserted by code assist is more annoying than useful to me. It is meant to save the user to type it in case there are more parameters to add, but in fact it ends up to allow the user to type just as many characters as he/she has to type if he/she manually inserts ", " after each parameter, which is way more natural for me.

Suppose you want to call:
def b = new MyBean(foo: 'foo', bar: 'bar')
and you start from:
def b = new MyBean(
currently, you have to type (let's assume string constants are just one key):
(1) Ctrl+Space, (2) down arrow (to choose foo:), (3) Enter (to accept foo:), (4) 'foo', (5) TAB, (6) Ctrl+Space, (7) Enter (to accept bar:), (8) 'bar', (9) TAB, (10) backspace (to remove trailing space), (11) backspace (to remove trailing comma), (12) closed parenthesis
You can save 2 keys if at point (9) you remember to hit DEL (instead of TAB) and then you close parenthesis.
So, currently you have to type 12 or 10 keys.

If there were no trailing comma and space, you will have to type:
(1) Ctrl+Space, (2) down arrow (to choose foo:), (3) Enter (to accept foo:), (4) 'foo', (5) comma, (6) space, (7) Ctrl+Space, (8) Enter (to accept bar:), (9) 'bar', (10) closed parenthesis.
If you don't want the space between fields, you'll have one less key to type.

So, in the worst case, you have to type the same amount of characters.
Fact is that it's unnatural to me to remember to press TAB and DEL to properly complete this kind of statement. I would very much prefer to have full control over commas and spaces between fields.

The only case in which I find the insertion of the trailing ", " useful is when you're accepting a suggestion for a parameter which is not the last one, i.e. suppose you have MyBean.setBaz(String) as well and you are at:
def b = new MyBean(foo: 'foo', | bar: 'bar')
when you invoke code assist at "|" and accept baz: the result is:
def b = new MyBean(foo: 'foo', baz: __, bar: 'bar')
(although please note how the trailing space is still redundant, because it adds an extra space before the next field).

So, maybe an option to disable the automatic ", " insertion, at least for the last field in a map-style constructor invocation (or to disable it completely) would be very appreciated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions