Index: pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart |
index c6e376a2c91ab8f453522dda00d922885d6bbed8..a2379acc4128c523e9f859c73451565cbecc2002 100644 |
--- a/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart |
+++ b/pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart |
@@ -25,14 +25,16 @@ const String DYNAMIC = 'dynamic'; |
* If the suggestion is not currently in scope, then specify |
* importForSource as the source to which an import should be added. |
*/ |
-CompletionSuggestion createSuggestion(Element element, |
- {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
+CompletionSuggestion createSuggestion(Element element, {String completion, |
+ CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
int relevance: DART_RELEVANCE_DEFAULT, Source importForSource}) { |
if (element is ExecutableElement && element.isOperator) { |
// Do not include operators in suggestions |
return null; |
} |
- String completion = element.displayName; |
+ if (completion == null) { |
+ completion = element.displayName; |
+ } |
bool isDeprecated = element.isDeprecated; |
CompletionSuggestion suggestion = new CompletionSuggestion(kind, |
isDeprecated ? DART_RELEVANCE_LOW : relevance, completion, |
@@ -189,7 +191,8 @@ abstract class ElementSuggestionBuilder { |
/** |
* Add a suggestion based upon the given element. |
*/ |
- void addSuggestion(Element element, {int relevance: DART_RELEVANCE_DEFAULT}) { |
+ void addSuggestion(Element element, |
+ {String prefix, int relevance: DART_RELEVANCE_DEFAULT}) { |
if (element.isPrivate) { |
LibraryElement elementLibrary = element.library; |
CompilationUnitElement unitElem = request.unit.element; |
@@ -201,18 +204,25 @@ abstract class ElementSuggestionBuilder { |
return; |
} |
} |
- if (element.isSynthetic) { |
+ if (prefix == null && element.isSynthetic) { |
if ((element is PropertyAccessorElement) || |
element is FieldElement && !_isSpecialEnumField(element)) { |
return; |
} |
} |
String completion = element.displayName; |
+ if (prefix != null && prefix.length > 0) { |
+ if (completion == null || completion.length <= 0) { |
+ completion = prefix; |
+ } else { |
+ completion = '$prefix.$completion'; |
+ } |
+ } |
if (completion == null || completion.length <= 0) { |
return; |
} |
- CompletionSuggestion suggestion = |
- createSuggestion(element, kind: kind, relevance: relevance); |
+ CompletionSuggestion suggestion = createSuggestion(element, |
+ completion: completion, kind: kind, relevance: relevance); |
if (suggestion != null) { |
request.addSuggestion(suggestion); |
} |
@@ -440,12 +450,18 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
final DartCompletionRequest request; |
final CompletionSuggestionKind kind; |
final bool typesOnly; |
+ final bool instCreation; |
- LibraryElementSuggestionBuilder(this.request, this.kind, this.typesOnly); |
+ LibraryElementSuggestionBuilder( |
+ this.request, this.kind, this.typesOnly, this.instCreation); |
@override |
visitClassElement(ClassElement element) { |
- addSuggestion(element); |
+ if (instCreation) { |
+ element.visitChildren(this); |
+ } else { |
+ addSuggestion(element); |
+ } |
} |
@override |
@@ -460,6 +476,19 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
} |
@override |
+ visitConstructorElement(ConstructorElement element) { |
+ if (instCreation) { |
+ ClassElement classElem = element.enclosingElement; |
+ if (classElem != null) { |
+ String prefix = classElem.name; |
+ if (prefix != null && prefix.length > 0) { |
+ addSuggestion(element, prefix: prefix); |
+ } |
+ } |
+ } |
+ } |
+ |
+ @override |
visitElement(Element element) { |
// ignored |
} |
@@ -473,7 +502,9 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
@override |
visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
- addSuggestion(element); |
+ if (!instCreation) { |
+ addSuggestion(element); |
+ } |
} |
@override |
@@ -487,10 +518,11 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor |
* Add suggestions for the visible members in the given library |
*/ |
static void suggestionsFor(DartCompletionRequest request, |
- CompletionSuggestionKind kind, LibraryElement library, bool typesOnly) { |
+ CompletionSuggestionKind kind, LibraryElement library, bool typesOnly, |
+ bool instCreation) { |
if (library != null) { |
- library.visitChildren( |
- new LibraryElementSuggestionBuilder(request, kind, typesOnly)); |
+ library.visitChildren(new LibraryElementSuggestionBuilder( |
+ request, kind, typesOnly, instCreation)); |
} |
} |
} |