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

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

Issue 1407273004: next step toward completion plugin API (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698