Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mauromol opened this issue Feb 20, 2018 · 2 comments
Closed
Assignees
Milestone

Comments

@mauromol
Copy link

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.

@eric-milles
Copy link
Member

Insertion of named parameter proposals without trailing comma-space is ready to test. If you trigger the proposal with , it should be inserted at the end of the completion. The comma was part of the completions for the longest time because the JDT components that have been leveraged for named parameter proposals did not insert the comma when typed and this made it difficult to complete multiple named parameters.

@eric-milles eric-milles changed the title Allow to disable the annoying trailing ", " inserted in map-style constructor call code assist Remove trailing ", " from map-style constructor call named argument proposals Feb 21, 2018
@eric-milles eric-milles added this to the v3.0.0 milestone Feb 21, 2018
@mauromol
Copy link
Author

mauromol commented Feb 22, 2018

Hi Eric,
I've tested with 3.0.0.xx-201802211752-e47 and the trailing ", " is not inserted any more, thanks a lot!!
However, triggering the proposal with , does not work for me (it seems like comma is not recognized as trigger character at all). Not that important for me...

@eric-milles eric-milles self-assigned this Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants