-
Notifications
You must be signed in to change notification settings - Fork 193
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
https://github.com/groovy/groovy-eclipse/issues/603 #622
Conversation
So what's the difference between |
Should it be Do you see a problem with 3 flags to control all this stuff? We have 8 possibilities at the moment and it would go to 16 if another option was added. Are the 3 options independently variable? If not, I would think some sort of Strategy pattern should be used instead and deprecate |
It seems like |
|
I'm not against freedom of choises/expression. What I am concerned with is too many combinations that are not really valid or useful. I'd prefer to see Also, your edits include changes to |
How far off is |
Here is my frustration: We did not really get a chance to discuss solution options for #603. Now I am having to review changes in hand, when I don't think we have completely understood the problem. |
As I mentioned useNamedArgs is used to force argument names for parameters. Does not seem to have anything related to the builder pattern. Here is the relevant snippet: Lines 285 to 294 in c9406f3
Example: Proposal generated: Note that |
Added missing tests for delegatesTo and tests against useNamedArgs with a builder on/off. |
Your first two examples in the initial comment can be attained with When method does not have trailing closure, isn't it for the user to decide if parenthesis are desired (via content assist pref)? Otherwise, I'm not sure I understand wanting parens in one case and not in another. What I am driving at is there are at least 2 settings in the DSLD and several more in content assist prefs to control this stuff. But you seem stuck on associating a tuple of these settings to 1 single flag. But if I get a request for another mix of settings how would I handle that? As I stated in #603, I'd prefer to tackle each of the content assist problems as separately as possible and I would choose new DSLD API as a last resort solution. It may be beneficial for named arguments or trailing closures in general to make a non-DSLD change. |
Regarding parens vs no parens - that is a pretty conventional Groovy builder approach:
Alternative which is provided by noParens is practically never used in builders:
|
Your example with
|
Note that besides formatting, isBuilder flag also triggers a trailing closure treatment as a code body. The closure is excluded from the argument editing mode, and the caret moves right inside the block as soon as editing is completed. |
I understand how each property works. I don't really want to read the book on builders. What is your use case that is not being met? You keep referring to builder syntax in the general sense. Can you break that down to specific items, one issue per item that is not achievable with current DSLD and content assist preferences? Personal preferences for completion and formatting should remain controllable by the user. I have a hard time with wanting to set content assist preferences a certain way and then override them under specific circumstances. If the user wants parameter guessing, why should it be disabled? Are you not able to join the Slack channel so we can have immediate back and forth so I can ask for examples and then ask about the examples that are shown? |
Please understand that I did not design the DSLD stuff, so I am having to live with some questionable choices like |
Regarding minimizing DSL API changes, doable but we would have to change behavior of noParens:
Are you ok with that? |
Is your top concern the trailing closure handling? If so, can you open a new issue just for that and describe current behavior and desired end state? |
In general, are you desiring to add method contributions with |
Right now, I am unable to explore the problem space and experiment with possible solutions. I would like to see the problem space divided up, instead of just dealing with "builder syntax" in its entirety. |
Yes, exactly I have only these 2 concerns:
|
So for 1, what is the conflict? In general do you want to add methods that omit parens, but with trailing closures, you want them? Can't the trailing closure methods be specified without a |
With noParens used, parens surround the trailing closure: This is the default eclipse behavior. You can get it very close if you enable It will turn to Or if It will turn to Here is the problem with code assist preferences:
|
Is It sounds like the desire is to override content assist preferences to prevent requiring user make specific setting adjustments. If you want templates, there is a templating system. They would not be context sensitive -- meaning you could not specify in which context a particular template applies. They would all be proposed at all levels as long as the completion expression prefix matches. |
Yes |
If you want If you want The block could be replaced with a closure literal either because this is a DSLD contrib or because the name convention. I have thought that a name inserted outside the parens is pretty useless. Maybe we could just fix that in all cases. Thoughts? |
For this proposal, I am turning a blind eye towards the guessing preferences. Also, as you mentioned in your summary, checking "Use closure literals for closure arguments" yields: |
I definitely do not want foo(bar: something) { } when bar is a regular parameter, only when it is a named one. |
Sorry, i think we hit "Comment" at the same time :) Ok, so what about just naming convention that would trigger:
|
Okay, I am sensing you want immunity from user's content assist preferences. But can we ignore the guessing stuff for now? And is it so bad to require the user to check "Place trailing closure arguments after closing parenthesis"? It would still be functional syntax to have the block inside (though not idiomatic or whatever). I can see ignoring the setting for "Use closure literals" and just provide the literal since it is required for correct syntax when outside the parens. So, if we fixed that up, would there even be a need for a name convention? |
Assuming "Place trailing closure arguments after closing parenthesis" is checked, I see 2 small issues to write up and fix first:
Fair enough? |
Not ideal. DSLD would have to come with extra instructions on how to make them work really. |
The 2 non-default guessing modes can either continue to work as they do or ignore user preferences... I'd prefer the first option. |
Or just fixing non-idiomatic noParens trailing closure use case? |
But see, if "Place trailing closure arguments after closing parenthesis" is in its default state, you get working code. Either I don't see |
Like I sad above, first steps are to assume a base state. We can cover more permutations of content assust prefs later. |
it does work but that kind of code practice |
If I set noParens to true and got parens I'd be scratching my head. |
That would be only limited to trailing closure use cases, which will be apparent to not have parens. |
We could set "Place trailing closure arguments after closing parenthesis" as default checked too. |
Do my 2 proposed issues seem like a reasonable first step? I think they would be easy to code up, test and review. Then we could regroup on remaining gaps/issues. |
Defaults would be fine with me, hopefully it is not going to be too radical... |
that would leave us with |
Would you like to write these up as new issues or would you like me to do it? We'll put non-default guessing aside for now and leave noParens as-is.
|
At this point I am not seeing a DSLD API change; the fixes would apply for method completion when the preferences are in the state described. |
DSLD method contributions appear to be immune to "Use named arguments for method calls" pref, so that's one less pref to worry about. |
One additional note, if "Place trailing closure arguments after closing parenthesis" is checked and "Use closure literals for closure arguments" is unchecked, typing |
I can check handling of '{' as a trigger, but |
Anyways I will refactor PR, to fix just issues you outlined and the we can resume brainstorming from there. |
I'm not saying the I'm asking for 2 issues to be created and new PRs coded, tested and reviewed for them. This PR can be left alone, in case you want to look at your changes again. |
to clarify, you want one issue for checked state of the “use closure literal” option and another for unchecked to both end up with { }, and 2 PRs, that granular? |
A new boolean property
isBuilder
has been added to themethod
contribution.When it is not specified or set to false, the existing behavior is completely preserved.
isBuilder
is similar tonoParens
. It removes parentheses around arguments, however parentheses are forced when the method has a trailing closure.When isBuilder=true is specified, the following behavior is expected:
e.g.
method name: 'bar', type: 'void', isBuilder: true, params: ['block':Closure]
bar { | }
e.g.
method name: 'bar', type: 'void', isBuilder: true, namedParams:['name':String], params: ['block':Closure]
noParens=true
e.g.
method name: 'bar', type: 'void', isBuilder: true, namedParams:['name':String], params: ['regular':String]
The resulting proposal will look like the following:
bar name: name, regular
The above change will make groovy builders generally expressed in DSLD. Also it will make builders less time consuming and less confusing to use by DSLD consumers.