Index: pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart |
index 98dd66b39a3764e6afed37693b00c5da37c6fc25..e0f470534211deb7979c2a8ec487588914b5a332 100644 |
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart |
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart |
@@ -8,7 +8,8 @@ import 'dart:async'; |
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart'; |
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart'; |
-import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'; |
+import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart' |
+ show createSuggestion, ElementSuggestionBuilder; |
import 'package:analysis_server/src/services/completion/optype.dart'; |
import 'package:analyzer/src/generated/ast.dart'; |
import 'package:analyzer/src/generated/element.dart'; |
@@ -34,9 +35,9 @@ class LocalLibraryContributor extends DartCompletionContributor { |
return EMPTY_LIST; |
} |
- List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; |
OpType optype = (request as DartCompletionRequestImpl).opType; |
- _Visitor visitor = new _Visitor(request, optype, suggestions); |
+ LibraryElementSuggestionBuilder visitor = |
+ new LibraryElementSuggestionBuilder(request, optype); |
if (request.librarySource != request.source) { |
request.libraryElement.definingCompilationUnit.accept(visitor); |
} |
@@ -48,7 +49,7 @@ class LocalLibraryContributor extends DartCompletionContributor { |
} |
} |
} |
- return suggestions; |
+ return visitor.suggestions; |
} |
} |
@@ -57,21 +58,28 @@ class LocalLibraryContributor extends DartCompletionContributor { |
* a source file contained in the same library but not the same as |
* the source in which the completions are being requested. |
*/ |
-class _Visitor extends GeneralizingElementVisitor { |
+class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
+ with ElementSuggestionBuilder { |
final DartCompletionRequest request; |
final OpType optype; |
- final List<CompletionSuggestion> suggestions; |
+ CompletionSuggestionKind kind; |
+ final String prefix; |
+ List<String> showNames; |
+ List<String> hiddenNames; |
+ |
+ LibraryElementSuggestionBuilder(this.request, this.optype, [this.prefix]) { |
+ this.kind = request.target.isFunctionalArgument() |
+ ? CompletionSuggestionKind.IDENTIFIER |
+ : CompletionSuggestionKind.INVOCATION; |
+ } |
- _Visitor(this.request, this.optype, this.suggestions); |
+ @override |
+ LibraryElement get containingLibrary => request.libraryElement; |
@override |
void visitClassElement(ClassElement element) { |
if (optype.includeTypeNameSuggestions) { |
- CompletionSuggestion suggestion = |
- createSuggestion(element, relevance: DART_RELEVANCE_DEFAULT); |
- if (suggestion != null) { |
- suggestions.add(suggestion); |
- } |
+ addSuggestion(element, prefix: prefix, relevance: DART_RELEVANCE_DEFAULT); |
} |
if (optype.includeConstructorSuggestions) { |
_addConstructorSuggestions(element, DART_RELEVANCE_DEFAULT); |
@@ -97,19 +105,17 @@ class _Visitor extends GeneralizingElementVisitor { |
if (element.enclosingElement is! CompilationUnitElement) { |
return; |
} |
- int relevance = DART_RELEVANCE_LOCAL_FUNCTION; |
- CompletionSuggestion suggestion = |
- createSuggestion(element, relevance: relevance); |
- if (suggestion != null) { |
- DartType returnType = element.returnType; |
- if (returnType != null && returnType.isVoid) { |
- if (optype.includeVoidReturnSuggestions) { |
- suggestions.add(suggestion); |
- } |
- } else { |
- if (optype.includeReturnValueSuggestions) { |
- suggestions.add(suggestion); |
- } |
+ int relevance = element.library == containingLibrary |
+ ? DART_RELEVANCE_LOCAL_FUNCTION |
+ : DART_RELEVANCE_DEFAULT; |
+ DartType returnType = element.returnType; |
+ if (returnType != null && returnType.isVoid) { |
+ if (optype.includeVoidReturnSuggestions) { |
+ addSuggestion(element, prefix: prefix, relevance: relevance); |
+ } |
+ } else { |
+ if (optype.includeReturnValueSuggestions) { |
+ addSuggestion(element, prefix: prefix, relevance: relevance); |
} |
} |
} |
@@ -117,22 +123,40 @@ class _Visitor extends GeneralizingElementVisitor { |
@override |
void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
if (optype.includeTypeNameSuggestions) { |
- CompletionSuggestion suggestion = |
- createSuggestion(element, relevance: DART_RELEVANCE_LOCAL_FUNCTION); |
- if (suggestion != null) { |
- suggestions.add(suggestion); |
+ int relevance = element.library == containingLibrary |
+ ? DART_RELEVANCE_LOCAL_FUNCTION |
+ : DART_RELEVANCE_DEFAULT; |
+ addSuggestion(element, prefix: prefix, relevance: relevance); |
+ } |
+ } |
+ |
+ @override |
+ void visitLibraryElement(LibraryElement element) { |
+ element.visitChildren(this); |
+ } |
+ |
+ @override |
+ void visitPropertyAccessorElement(PropertyAccessorElement element) { |
+ int relevance; |
+ if (element.library == containingLibrary) { |
+ if (element.enclosingElement is ClassElement) { |
+ relevance = DART_RELEVANCE_LOCAL_FIELD; |
+ } else { |
+ relevance = DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE; |
} |
+ } else { |
+ relevance = DART_RELEVANCE_DEFAULT; |
} |
+ addSuggestion(element, prefix: prefix, relevance: relevance); |
} |
@override |
void visitTopLevelVariableElement(TopLevelVariableElement element) { |
if (optype.includeReturnValueSuggestions) { |
- CompletionSuggestion suggestion = createSuggestion(element, |
- relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); |
- if (suggestion != null) { |
- suggestions.add(suggestion); |
- } |
+ int relevance = element.library == containingLibrary |
+ ? DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE |
+ : DART_RELEVANCE_DEFAULT; |
+ addSuggestion(element, prefix: prefix, relevance: relevance); |
} |
} |
@@ -148,6 +172,9 @@ class _Visitor extends GeneralizingElementVisitor { |
if (suggestion != null) { |
String name = suggestion.completion; |
name = name.length > 0 ? '$className.$name' : className; |
+ if (prefix != null && prefix.length > 0) { |
+ name = '$prefix.$name'; |
+ } |
suggestion.completion = name; |
suggestion.selectionOffset = suggestion.completion.length; |
suggestions.add(suggestion); |