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

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/local_constructor_contributor.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
« 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_constructor_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_constructor_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_constructor_contributor.dart
index eb527a4250b7a9db38e599678814b8e8a68fc275..f51aa26cc097825d0cd052f221f4721e1bfb38a4 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_constructor_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_constructor_contributor.dart
@@ -165,8 +165,23 @@ class LocalConstructorContributor extends DartCompletionContributor {
List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
if (!optype.isPrefixed) {
if (optype.includeConstructorSuggestions) {
- _Visitor visitor = new _Visitor(request, suggestions);
- visitor.visit(request.target.containingNode);
+ AstNode node = request.target.containingNode;
+ // TODO (jwren) not quite right, see the test
+ // test_InstanceCreationExpression_variable_declaration_filter,
+ // the node at this point is an InstanceCreationExpression, but we want
+ // the containing variable declaration resolved,
+ if (node is Expression) {
+ while (node.parent is Expression) {
+ node = node.parent;
+ }
+ await request.resolveExpression(node);
+
+ // Discard any cached target information
+ // because it may have changed as a result of the resolution
+ node = request.target.containingNode;
+ }
+ _Visitor visitor = new _Visitor(request, suggestions, optype);
+ visitor.visit(node);
}
}
return suggestions;
@@ -178,9 +193,10 @@ class LocalConstructorContributor extends DartCompletionContributor {
*/
class _Visitor extends LocalDeclarationVisitor {
final DartCompletionRequest request;
+ final OpType optype;
final List<CompletionSuggestion> suggestions;
- _Visitor(DartCompletionRequest request, this.suggestions)
+ _Visitor(DartCompletionRequest request, this.suggestions, this.optype)
: request = request,
super(request.offset);
@@ -236,6 +252,14 @@ class _Visitor extends LocalDeclarationVisitor {
ClassDeclaration classDecl, ConstructorDeclaration constructorDecl) {
String completion = classDecl.name.name;
SimpleIdentifier elemId;
+ int relevance = DART_RELEVANCE_DEFAULT;
+
+ int filter = optype.constructorSuggestionsFilter(classDecl.element?.type);
+ if (filter == null) {
+ return;
+ } else {
+ relevance += filter;
+ }
// Build a suggestion for explicitly declared constructor
if (constructorDecl != null) {
@@ -248,8 +272,8 @@ class _Visitor extends LocalDeclarationVisitor {
}
}
if (elem != null) {
- CompletionSuggestion suggestion =
- createSuggestion(elem, completion: completion);
+ CompletionSuggestion suggestion = createSuggestion(elem,
+ completion: completion, relevance: relevance);
if (suggestion != null) {
suggestions.add(suggestion);
}
@@ -264,7 +288,7 @@ class _Visitor extends LocalDeclarationVisitor {
element.returnType = classDecl.name.name;
CompletionSuggestion suggestion = new CompletionSuggestion(
CompletionSuggestionKind.INVOCATION,
- DART_RELEVANCE_DEFAULT,
+ relevance,
completion,
completion.length,
0,
« 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