Index: pkg/analysis_server/lib/src/provisional/completion/dart/completion_plugin.dart |
diff --git a/pkg/analysis_server/lib/src/provisional/completion/dart/completion_plugin.dart b/pkg/analysis_server/lib/src/provisional/completion/dart/completion_plugin.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7a21bbb66137fd30b655964c0d14f6330265405b |
--- /dev/null |
+++ b/pkg/analysis_server/lib/src/provisional/completion/dart/completion_plugin.dart |
@@ -0,0 +1,71 @@ |
+// 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 analysis_server.src.provisional.completion.dart.plugin; |
+ |
+import 'package:analysis_server/src/provisional/completion/dart/completion.dart'; |
+import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart'; |
+import 'package:analysis_server/src/services/completion/dart/keyword_contributor.dart'; |
+import 'package:plugin/plugin.dart'; |
+ |
+/** |
+ * The shared dart completion plugin instance. |
+ */ |
+final DartCompletionPlugin dartCompletionPlugin = new DartCompletionPlugin(); |
Brian Wilkerson
2015/11/30 18:10:27
I'm not thrilled about having a global variable, b
danrubel
2015/11/30 18:53:38
The linter plugin does this as well. If we have a
|
+ |
+class DartCompletionPlugin implements Plugin { |
Brian Wilkerson
2015/11/30 18:10:27
What's the value of pulling this out to a separate
danrubel
2015/11/30 18:53:38
There will be a top level CompletionContributor ex
Brian Wilkerson
2015/11/30 19:02:01
I assume that will be in the server plugin, in whi
|
+ /** |
+ * The simple identifier of the extension point that allows plugins to |
+ * register Dart specific completion contributor factories. |
+ * Use [DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID] |
+ * when registering contributors. |
+ */ |
+ static const String CONTRIBUTOR_EXTENSION_POINT = 'contributor'; |
+ |
+ /** |
+ * The unique identifier of this plugin. |
+ */ |
+ static const String UNIQUE_IDENTIFIER = 'dart.completion'; |
+ |
+ /** |
+ * The extension point that allows plugins to register Dart specific |
+ * completion contributor factories. |
+ */ |
+ ExtensionPoint _contributorExtensionPoint; |
+ |
+ @override |
+ String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
+ |
+ /** |
+ * Return a list containing all of the Dart specific completion contributor |
+ * factories that were contributed. |
+ */ |
+ List<DartCompletionContributorFactory> get contributorFactories => |
+ _contributorExtensionPoint.extensions; |
+ |
+ @override |
+ void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
+ _contributorExtensionPoint = registerExtensionPoint( |
+ CONTRIBUTOR_EXTENSION_POINT, |
+ _validateDartCompletionContributorExtension); |
+ } |
+ |
+ @override |
+ void registerExtensions(RegisterExtension registerExtension) { |
+ registerExtension(DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, |
+ () => new KeywordContributor()); |
+ } |
+ |
+ /** |
+ * Validate the given extension by throwing an [ExtensionError] if it is not a |
+ * valid Dart specific completion contributor. |
+ */ |
+ void _validateDartCompletionContributorExtension(Object extension) { |
+ if (extension is! DartCompletionContributorFactory) { |
+ String id = _contributorExtensionPoint.uniqueIdentifier; |
+ throw new ExtensionError( |
+ 'Extensions to $id must be a DartCompletionContributorFactory'); |
+ } |
+ } |
+} |