-
Notifications
You must be signed in to change notification settings - Fork 314
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
Completions on named arguments should include trailing comma #551
Comments
I speculate this was not done before as the last named argument was not allowed to have a terminating comma, but now that this is allowed I think this would be very valuable. |
A thought (from @mit-mit): what if we always insert trailing commas for methods w/ named params w/ two or more args? This would be for when you're calling a ctor and you are setting 2 or more params. Likely also for lists. |
This seems to be already fixed, can you please double check?
With auto-inserted comma or without it analyzer is giving an error
Phil's PR is almost ready, but before finishing it up and landing I'd like to understand the rationale behind this feature. Sorry, I failed to guess what becomes better with this feature :). |
I'll take a quick stab but hopefully @mit-mit will chime in. A compelling benefit in ensuring trailing commas for Flutter is in how they trigger the formatter. The formatter is trained to handle trailing commas in such a way that makes formatted constructor invocations that include lots of nested args look like idiomatic Flutter if there are trailing commas. For example, compare with trailing commas,
to without:
The nested structure is clearer in the first. |
Thanks, makes sense. I have good news! You do not need any PR to land in the Dart plugin to get this functionality. You'll notice though that the caret is placed after comma on such item selection, whereas the caret before comma is expected. This also seems to be a server-side issue. It sends incorrect CompletionSuggestion.selectionOffset. |
OK, great. We agree! I also think this would better implemented on the server side. 👍 I talked myself out of it since I thought we might want a preference and that lead to me thinking it would all be easier on the client side. But anyway, I agree, so I'll go back to that approach since it has a bunch of other advantages. As for your experience, I'm curious what version of the SDK you have. I'm on |
however, even the old Dart SDK 1.19 does the same |
The behavior appears to differ depending on whether you complete on "nothing" (ctrl-space) or on an actual completion such as 'b' in Phil's screenshot? |
We may want a preference and may implement all on the client side. But we should agree with server first. What I think we definitely wouldn't like to have is to have trailing commas in some cases coming from the server, in other cases - added by client.
Wow, indeed! Not sure what rationale is behind. |
👍 I'll look into this as I move towards implementing this support on the server side. |
Related to: flutter/flutter-intellij#551 * fixes named arg selection offset to precede comma * fixes inconsistent trailing commas between completions w/ and w/o prefixes BUG= R=brianwilkerson@google.com Review-Url: https://codereview.chromium.org/2839273002 .
…ntellij#551). * adds trailing commas to named params in Flutter instance creations * adds trailing commas to default value boilerplate See flutter/flutter-intellij#551 for action shots. :) R=brianwilkerson@google.com Review-Url: https://codereview.chromium.org/2850693002 .
Implemented w/ dart-lang/sdk@bfc071e. |
@pq when will we see this in the product? |
The next push of the flutter SDK. |
Repro steps:
main.dart
place the cursor at the end of line 77 (title: new Text(config.title),
)back
and then Enter to select thebackgroundColor
completionExpected result:
backgroundColor: ,
and the caret is placed just before,
Actual result:
backgroundColor:
resulting in the completed code triggering an analyzer errorThe text was updated successfully, but these errors were encountered: