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

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

Issue 1882243003: Code completion improvement: in NamedExpressions (m(someNamedParam: ^)), use type information to so… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Comments from DanR 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 d5f206c75454081d628fce18a86115759bd56dd9..db100b46d437990adc441c9e33ab7b41a822adca 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -5,6 +5,7 @@
library services.completion.dart.optype;
import 'package:analysis_server/src/protocol_server.dart' hide Element;
+import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
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';
@@ -32,7 +33,7 @@ class OpType {
/**
* If [includeTypeNameSuggestions] is set to true, then this function may be
- * set to the non-default function to filter out potential suggestions based
+ * set to a non-default function to filter out potential suggestions based
* on their static [DartType].
*/
Function typeNameSuggestionsFilter = (DartType _) => true;
@@ -50,6 +51,14 @@ class OpType {
bool includeReturnValueSuggestions = false;
/**
+ * If [includeReturnValueSuggestions] is set to true, then this function may
+ * be set to a non-default function to filter out potential suggestions (null)
+ * based on their static [DartType], or change the relative relevance by
+ * returning a positive or negative integer.
+ */
+ Function returnValueSuggestionsFilter = (DartType _) => 0;
+
+ /**
* Indicates whether named arguments should be suggested.
*/
bool includeNamedArgumentSuggestions = false;
@@ -433,7 +442,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
optype.includeVoidReturnSuggestions = true;
// TODO (danrubel) void return suggestions only belong after
// the 2nd semicolon. Return value suggestions only belong after the
- // e1st or second semicolon.
+ // first or second semicolon.
}
@override
@@ -548,6 +557,14 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
void visitNamedExpression(NamedExpression node) {
if (identical(entity, node.expression)) {
optype.includeReturnValueSuggestions = true;
+ optype.returnValueSuggestionsFilter = (DartType dartType) {
+ DartType type = node.element?.type;
+ bool isCorrectType = type != null &&
+ dartType != null &&
+ !type.isDynamic &&
+ dartType.isSubtypeOf(type);
+ return isCorrectType ? DART_RELEVANCE_INCREMENT : 0;
+ };
optype.includeTypeNameSuggestions = true;
}
}

Powered by Google App Engine
This is Rietveld 408576698