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

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

Issue 2722253002: Calculate default args for local reference completions. (Closed)
Patch Set: Cleanup; added test. Created 3 years, 10 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/completion_contributor_util.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/local_reference_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
index ae669006a4b522b0cfbac074dfaa806fa8e04ae5..bbe9d33a09d48f826ba5f2ab02fee3ee9a8786a6 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
@@ -470,11 +470,30 @@ class _LocalVisitor extends LocalDeclarationVisitor {
// TODO(brianwilkerson) Support function types.
return 'dynamic';
}).toList();
- suggestion.requiredParameterCount = paramList
- .where((FormalParameter param) => param is! DefaultFormalParameter)
- .length;
- suggestion.hasNamedParameters = paramList
- .any((FormalParameter param) => param.kind == ParameterKind.NAMED);
+
+ Iterable<ParameterElement> requiredParameters = paramList
+ .where((FormalParameter param) => param.kind == ParameterKind.REQUIRED)
+ .map((p) => p.element);
+ suggestion.requiredParameterCount = requiredParameters.length;
+
+ Iterable<ParameterElement> namedParameters = paramList
+ .where((FormalParameter param) => param.kind == ParameterKind.NAMED)
+ .map((p) => p.element);
+ suggestion.hasNamedParameters = namedParameters.isNotEmpty;
+
+ suggestion.defaultArgumentListString =
+ _buildDefaultArgList(requiredParameters, namedParameters);
+ }
+
+ String _buildDefaultArgList(Iterable<ParameterElement> requiredParams,
+ Iterable<ParameterElement> namedParams) {
+ List<String> args = requiredParams.map((p) => p.name).toList();
+ List<String> requiredArgs = namedParams
+ .where((p) => p.isRequired)
+ .map((p) => '${p.name}: null')
+ .toList();
+ args.addAll(requiredArgs);
+ return args.join(', ');
}
bool _isVoid(TypeAnnotation returnType) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698