Index: pkg/analysis_server/lib/src/services/completion/dart/dart_completion_manager.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_manager.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..49efd7ec68c5a5358081bfc91c6e469d81ae24a7 |
--- /dev/null |
+++ b/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_manager.dart |
@@ -0,0 +1,75 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library services.completion.computer.dart.manager; |
+ |
+import 'package:analysis_server/plugin/protocol/protocol.dart' |
+ show CompletionSuggestion, CompletionSuggestionKind; |
+import 'package:analysis_server/src/provisional/completion/completion_dart.dart'; |
+import 'package:analysis_server/src/services/completion/dart_completion_manager.dart' |
+ show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOCAL_FUNCTION; |
+import 'package:analysis_server/src/services/completion/suggestion_builder.dart'; |
+import 'package:analyzer/src/generated/element.dart'; |
+ |
+// TODO (danrubel) revise a move existing manager to this file |
+ |
+/** |
+ * An internal implementation of [DartSuggestionCollector] for building |
+ * and collecting suggestions based upon elements. |
+ */ |
+class DartSuggestionCollectorImpl implements DartSuggestionCollector { |
+ List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; |
+ |
+ @override |
+ void addCompletionSuggestion(CompletionSuggestion suggestion) { |
+ if (suggestion != null) { |
+ suggestions.add(suggestion); |
+ } |
+ } |
+ |
+ @override |
+ void addElementSuggestion(Element element, |
+ {bool includePrivateElements: false, |
+ String prefix, |
+ int relevance: DART_RELEVANCE_DEFAULT}) { |
+ if (element.isPrivate && !includePrivateElements) { |
+ return; |
+ } |
+ 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; |
+ } |
+ addCompletionSuggestion(createSuggestion(element, |
+ completion: completion, |
+ kind: CompletionSuggestionKind.IDENTIFIER, |
+ relevance: relevance)); |
+ } |
+ |
+ /** |
+ * Determine if the given element is one of the synthetic enum accessors |
+ * for which we should generate a suggestion. |
+ */ |
+ bool _isSpecialEnumField(FieldElement element) { |
+ Element parent = element.enclosingElement; |
+ if (parent is ClassElement && parent.isEnum) { |
+ if (element.name == 'values') { |
+ return true; |
+ } |
+ } |
+ return false; |
+ } |
+} |