Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1022)

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart

Issue 2850693002: Trailing commas for named args in Flutter cons invocations (flutter-intellij#551). (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
index a179311633dce22b0642c9669c4ca0d06e0b4081..01775a3221b3737590a19959907318177ba623e3 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
@@ -277,6 +277,9 @@ class ArgListContributor extends DartCompletionContributor {
sb.write('${parameter.name}: ');
int offset = sb.length;
sb.write(defaultValue);
+ if (appendComma) {
+ sb.write(',');
+ }
suggestion.defaultArgumentListString = sb.toString();
suggestion.defaultArgumentListTextRanges = [
offset,
@@ -302,16 +305,14 @@ class ArgListContributor extends DartCompletionContributor {
// method which returns some enum with 5+ cases.
if (_isEditingNamedArgLabel(request) || _isAppendingToArgList(request)) {
if (requiredCount == 0 || requiredCount < _argCount(request)) {
- _addDefaultParamSuggestions(parameters);
+ bool addTrailingComma =
+ !_isFollowedByAComma(request) && _isInFlutterCreation(request);
+ _addDefaultParamSuggestions(parameters, addTrailingComma);
}
} else if (_isInsertingToArgListWithNoSynthetic(request)) {
_addDefaultParamSuggestions(parameters, true);
} else if (_isInsertingToArgListWithSynthetic(request)) {
- var entity = request.target.entity;
- Token token =
- entity is AstNode ? entity.endToken : entity is Token ? entity : null;
- bool followedByComma = token?.next?.type == TokenType.COMMA;
- _addDefaultParamSuggestions(parameters, !followedByComma);
+ _addDefaultParamSuggestions(parameters, !_isFollowedByAComma(request));
}
}
@@ -328,6 +329,21 @@ class ArgListContributor extends DartCompletionContributor {
return null;
}
+ bool _isFollowedByAComma(DartCompletionRequest request) {
+ var entity = request.target.entity;
+ Token token =
+ entity is AstNode ? entity.endToken : entity is Token ? entity : null;
+ return token?.next?.type == TokenType.COMMA;
+ }
+
+ bool _isInFlutterCreation(DartCompletionRequest request) {
+ AstNode containingNode = request?.target?.containingNode;
+ InstanceCreationExpression newExpr = containingNode != null
+ ? identifyNewExpression(containingNode.parent)
+ : null;
+ return newExpr != null && isFlutterInstanceCreationExpression(newExpr);
+ }
+
/**
* If the given [comment] is not `null`, fill the [suggestion] documentation
* fields.
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698