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

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

Issue 1871073003: Fix for issue 22357: use type information on the RHS of is expressions to improve quality of comple… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Comments from DanR- only resolve if the request containing node is an Expression 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/optype.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 6c20b0b97fa934d5d7bd59bfb471686aad350098..cf1977e37706b46d044bbf0c5f4932ef1bb7eabe 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
@@ -17,6 +17,8 @@ import 'package:analysis_server/src/services/completion/dart/optype.dart';
import 'package:analysis_server/src/services/correction/strings.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind;
@@ -161,6 +163,10 @@ class LocalReferenceContributor extends DartCompletionContributor {
// Do not suggest local vars within the current expression
while (node is Expression) {
+ // If node is an Expression, ensure that it is resolved. Resolution is
+ // used in cases such as the use of optype.typeNameSuggestionsFilter
+ // below.
+ await request.resolveExpression(node);
node = node.parent;
}
@@ -388,7 +394,14 @@ class _LocalVisitor extends LocalDeclarationVisitor {
suggestion.completion.startsWith('_')) {
suggestion.relevance = privateMemberRelevance;
}
- suggestionMap.putIfAbsent(suggestion.completion, () => suggestion);
+ // if includeTypeNameSuggestions, then use the filter
+ if (optype.includeTypeNameSuggestions) {
+ if (optype.typeNameSuggestionsFilter(_staticTypeOfIdentifier(id))) {
+ suggestionMap.putIfAbsent(suggestion.completion, () => suggestion);
+ }
+ } else {
+ suggestionMap.putIfAbsent(suggestion.completion, () => suggestion);
+ }
suggestion.element = _createLocalElement(request.source, elemKind, id,
isAbstract: isAbstract,
isDeprecated: isDeprecated,
@@ -448,4 +461,12 @@ class _LocalVisitor extends LocalDeclarationVisitor {
}
return false;
}
+
+ DartType _staticTypeOfIdentifier(Identifier id) {
+ if (id.staticElement is ClassElement) {
+ return (id.staticElement as ClassElement).type;
+ } else {
+ return id.staticType;
+ }
+ }
}
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/optype.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698