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

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

Issue 1867063003: show only named argument suggestions - fixes #25198, fixes #23992 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
Index: pkg/analysis_server/lib/src/services/completion/dart/optype.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
index e61845ef2c76744b6effee265d1207e891c42f5c..42f45c5d7f371c6dacc7d00b090b2c5871d0d12b 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -4,12 +4,14 @@
library services.completion.dart.optype;
-import 'package:analysis_server/src/protocol_server.dart';
+import 'package:analysis_server/src/protocol_server.dart' hide Element;
import 'package:analysis_server/src/provisional/completion/dart/completion_target.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
+import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/ast/token.dart';
+import 'package:analyzer/src/generated/utilities_dart.dart';
/**
* An [AstVisitor] for determining whether top level suggestions or invocation
@@ -40,6 +42,11 @@ class OpType {
bool includeReturnValueSuggestions = false;
/**
+ * Indicates whether named arguments should be suggested.
+ */
+ bool includeNamedArgumentSuggestions = false;
+
+ /**
* Indicates whether statement labels should be suggested.
*/
bool includeStatementLabelSuggestions = false;
@@ -86,6 +93,16 @@ class OpType {
*/
bool get includeOnlyTypeNameSuggestions =>
includeTypeNameSuggestions &&
+ !includeNamedArgumentSuggestions &&
+ !includeReturnValueSuggestions &&
+ !includeVoidReturnSuggestions;
+
+ /**
+ * Indicate whether only type names should be suggested
+ */
+ bool get includeOnlyNamedArgumentSuggestions =>
+ includeNamedArgumentSuggestions &&
+ !includeTypeNameSuggestions &&
!includeReturnValueSuggestions &&
!includeVoidReturnSuggestions;
}
@@ -123,6 +140,31 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@override
void visitArgumentList(ArgumentList node) {
+ AstNode parent = node.parent;
+ if (parent is InvocationExpression) {
+ Expression function = parent.function;
+ if (function is SimpleIdentifier) {
+ var elem = function.bestElement;
+ if (elem is FunctionTypedElement) {
+ List<ParameterElement> parameters = elem.parameters;
+ if (parameters != null) {
+ int index =
+ node.arguments.isEmpty ? 0 : node.arguments.indexOf(entity);
+ if (0 <= index && index < parameters.length) {
+ ParameterElement param = parameters[index];
+ if (param?.parameterKind == ParameterKind.NAMED) {
+ optype.includeNamedArgumentSuggestions = true;
+ return;
+ }
+ }
+ }
+ } else if (elem == null) {
+ // If unresolved, then include named arguments
+ optype.includeNamedArgumentSuggestions = true;
+ // fall through to include others as well
+ }
+ }
+ }
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
}

Powered by Google App Engine
This is Rietveld 408576698