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

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

Issue 1892823003: Code completion improvement, use type information when suggesting constructors (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: comments from danrubel 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 db100b46d437990adc441c9e33ab7b41a822adca..1908345dc172f185bfbd3dde26bda71b13da2a57 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -27,6 +27,14 @@ class OpType {
bool includeConstructorSuggestions = false;
/**
+ * If [includeConstructorSuggestions] 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 constructorSuggestionsFilter = (DartType _) => 0;
+
+ /**
* Indicates whether type names should be suggested.
*/
bool includeTypeNameSuggestions = false;
@@ -495,6 +503,27 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
void visitInstanceCreationExpression(InstanceCreationExpression node) {
if (identical(entity, node.constructorName)) {
optype.includeConstructorSuggestions = true;
+ optype.constructorSuggestionsFilter = (DartType dartType) {
+ DartType localTypeAssertion = null;
+ if(node.parent is VariableDeclaration) {
+ VariableDeclaration varDeclaration = node.parent as VariableDeclaration;
+ localTypeAssertion = varDeclaration.element.type;
+ } else if (node.parent is AssignmentExpression) {
+ AssignmentExpression assignmentExpression = node.parent as AssignmentExpression;
+ localTypeAssertion = assignmentExpression.leftHandSide.staticType;
+ }
+ if(localTypeAssertion == null ||
+ dartType == null ||
+ localTypeAssertion.isDynamic) {
+ return 0;
+ } else if (localTypeAssertion == dartType) {
+ return DART_RELEVANCE_INCREMENT;
+ } else if(dartType.isSubtypeOf(localTypeAssertion)) {
+ return 0;
+ } else {
+ return null;
+ }
+ };
}
}

Powered by Google App Engine
This is Rietveld 408576698