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

Side by Side Diff: pkg/analysis_server/lib/src/plugin/server_plugin.dart

Issue 1073383002: Create a public API for contributing assists and make assists pluggable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis_server.src.plugin.server_plugin; 5 library analysis_server.src.plugin.server_plugin;
6 6
7 import 'package:analysis_server/edit/assist/assist_core.dart';
7 import 'package:analysis_server/edit/fix/fix_core.dart'; 8 import 'package:analysis_server/edit/fix/fix_core.dart';
9 import 'package:analysis_server/plugin/assist.dart';
8 import 'package:analysis_server/plugin/fix.dart'; 10 import 'package:analysis_server/plugin/fix.dart';
9 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/domain_analysis.dart'; 12 import 'package:analysis_server/src/domain_analysis.dart';
11 import 'package:analysis_server/src/domain_completion.dart'; 13 import 'package:analysis_server/src/domain_completion.dart';
12 import 'package:analysis_server/src/domain_execution.dart'; 14 import 'package:analysis_server/src/domain_execution.dart';
13 import 'package:analysis_server/src/domain_server.dart'; 15 import 'package:analysis_server/src/domain_server.dart';
14 import 'package:analysis_server/src/edit/edit_domain.dart'; 16 import 'package:analysis_server/src/edit/edit_domain.dart';
15 import 'package:analysis_server/src/protocol.dart'; 17 import 'package:analysis_server/src/protocol.dart';
16 import 'package:analysis_server/src/search/search_domain.dart'; 18 import 'package:analysis_server/src/search/search_domain.dart';
19 import 'package:analysis_server/src/services/correction/assist_internal.dart';
17 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 20 import 'package:analysis_server/src/services/correction/fix_internal.dart';
18 import 'package:analyzer/plugin/plugin.dart'; 21 import 'package:analyzer/plugin/plugin.dart';
19 22
20 /** 23 /**
21 * A function that will create a request handler that can be used by the given 24 * A function that will create a request handler that can be used by the given
22 * [server]. 25 * [server].
23 */ 26 */
24 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); 27 typedef RequestHandler RequestHandlerFactory(AnalysisServer server);
25 28
26 /** 29 /**
27 * A plugin that defines the extension points and extensions that are inherently 30 * A plugin that defines the extension points and extensions that are inherently
28 * defined by the analysis server. 31 * defined by the analysis server.
29 */ 32 */
30 class ServerPlugin implements Plugin { 33 class ServerPlugin implements Plugin {
31 /** 34 /**
32 * The simple identifier of the extension point that allows plugins to 35 * The simple identifier of the extension point that allows plugins to
36 * register new assist contributors with the server.
37 */
38 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor';
39
40 /**
41 * The simple identifier of the extension point that allows plugins to
33 * register new domains with the server. 42 * register new domains with the server.
34 */ 43 */
35 static const String DOMAIN_EXTENSION_POINT = 'domain'; 44 static const String DOMAIN_EXTENSION_POINT = 'domain';
36 45
37 /** 46 /**
38 * The simple identifier of the extension point that allows plugins to 47 * The simple identifier of the extension point that allows plugins to
39 * register new fix contributors with the server. 48 * register new fix contributors with the server.
40 */ 49 */
41 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor'; 50 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor';
42 51
43 /** 52 /**
44 * The unique identifier of this plugin. 53 * The unique identifier of this plugin.
45 */ 54 */
46 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; 55 static const String UNIQUE_IDENTIFIER = 'analysis_server.core';
47 56
48 /** 57 /**
58 * The extension point that allows plugins to register new assist contributors
59 * with the server.
60 */
61 ExtensionPoint assistContributorExtensionPoint;
62
63 /**
49 * The extension point that allows plugins to register new domains with the 64 * The extension point that allows plugins to register new domains with the
50 * server. 65 * server.
51 */ 66 */
52 ExtensionPoint domainExtensionPoint; 67 ExtensionPoint domainExtensionPoint;
53 68
54 /** 69 /**
55 * The extension point that allows plugins to register new fix contributors 70 * The extension point that allows plugins to register new fix contributors
56 * with the server. 71 * with the server.
57 */ 72 */
58 ExtensionPoint fixContributorExtensionPoint; 73 ExtensionPoint fixContributorExtensionPoint;
59 74
60 /** 75 /**
61 * Initialize a newly created plugin. 76 * Initialize a newly created plugin.
62 */ 77 */
63 ServerPlugin(); 78 ServerPlugin();
64 79
65 @override 80 @override
66 String get uniqueIdentifier => UNIQUE_IDENTIFIER; 81 String get uniqueIdentifier => UNIQUE_IDENTIFIER;
67 82
68 /** 83 /**
84 * Return a list containing all of the fix contributors that were contributed.
85 */
86 List<AssistContributor> assistContributors() {
87 return assistContributorExtensionPoint.extensions;
88 }
89
90 /**
69 * Use the given [server] to create all of the domains ([RequestHandler]'s) 91 * Use the given [server] to create all of the domains ([RequestHandler]'s)
70 * that have been registered and return the newly created domains. 92 * that have been registered and return the newly created domains.
71 */ 93 */
72 List<RequestHandler> createDomains(AnalysisServer server) { 94 List<RequestHandler> createDomains(AnalysisServer server) {
73 if (domainExtensionPoint == null) { 95 if (domainExtensionPoint == null) {
74 return <RequestHandler>[]; 96 return <RequestHandler>[];
75 } 97 }
76 return domainExtensionPoint.extensions 98 return domainExtensionPoint.extensions
77 .map((RequestHandlerFactory factory) => factory(server)) 99 .map((RequestHandlerFactory factory) => factory(server))
78 .toList(); 100 .toList();
79 } 101 }
80 102
81 /** 103 /**
82 * Return a list containing all of the fix contributors that were contributed. 104 * Return a list containing all of the fix contributors that were contributed.
83 */ 105 */
84 List<FixContributor> fixContributors() { 106 List<FixContributor> fixContributors() {
85 return fixContributorExtensionPoint.extensions; 107 return fixContributorExtensionPoint.extensions;
86 } 108 }
87 109
88 @override 110 @override
89 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { 111 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {
112 assistContributorExtensionPoint = registerExtensionPoint(
113 ASSIST_CONTRIBUTOR_EXTENSION_POINT,
114 _validateAssistContributorExtension);
90 domainExtensionPoint = registerExtensionPoint( 115 domainExtensionPoint = registerExtensionPoint(
91 DOMAIN_EXTENSION_POINT, _validateDomainExtension); 116 DOMAIN_EXTENSION_POINT, _validateDomainExtension);
92 fixContributorExtensionPoint = registerExtensionPoint( 117 fixContributorExtensionPoint = registerExtensionPoint(
93 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); 118 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension);
94 } 119 }
95 120
96 @override 121 @override
97 void registerExtensions(RegisterExtension registerExtension) { 122 void registerExtensions(RegisterExtension registerExtension) {
98 // 123 //
124 // Register assist contributors.
125 //
126 registerExtension(
127 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor());
128 //
99 // Register domains. 129 // Register domains.
100 // 130 //
101 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); 131 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT);
102 registerExtension( 132 registerExtension(
103 domainId, (AnalysisServer server) => new ServerDomainHandler(server)); 133 domainId, (AnalysisServer server) => new ServerDomainHandler(server));
104 registerExtension( 134 registerExtension(
105 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server)); 135 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server));
106 registerExtension(domainId, 136 registerExtension(domainId,
107 (AnalysisServer server) => new EditDomainHandler(server, this)); 137 (AnalysisServer server) => new EditDomainHandler(server, this));
108 registerExtension( 138 registerExtension(
109 domainId, (AnalysisServer server) => new SearchDomainHandler(server)); 139 domainId, (AnalysisServer server) => new SearchDomainHandler(server));
110 registerExtension(domainId, 140 registerExtension(domainId,
111 (AnalysisServer server) => new CompletionDomainHandler(server)); 141 (AnalysisServer server) => new CompletionDomainHandler(server));
112 registerExtension(domainId, 142 registerExtension(domainId,
113 (AnalysisServer server) => new ExecutionDomainHandler(server)); 143 (AnalysisServer server) => new ExecutionDomainHandler(server));
114 // 144 //
115 // Register fix contributors. 145 // Register fix contributors.
116 // 146 //
117 registerExtension( 147 registerExtension(
118 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); 148 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor());
119 } 149 }
120 150
121 /** 151 /**
122 * Validate the given extension by throwing an [ExtensionError] if it is not a 152 * Validate the given extension by throwing an [ExtensionError] if it is not a
153 * valid fix contributor.
154 */
155 void _validateAssistContributorExtension(Object extension) {
156 if (extension is! AssistContributor) {
157 String id = assistContributorExtensionPoint.uniqueIdentifier;
158 throw new ExtensionError(
159 'Extensions to $id must be an AssistContributor');
160 }
161 }
162
163 /**
164 * Validate the given extension by throwing an [ExtensionError] if it is not a
123 * valid domain. 165 * valid domain.
124 */ 166 */
125 void _validateDomainExtension(Object extension) { 167 void _validateDomainExtension(Object extension) {
126 if (extension is! RequestHandlerFactory) { 168 if (extension is! RequestHandlerFactory) {
127 String id = domainExtensionPoint.uniqueIdentifier; 169 String id = domainExtensionPoint.uniqueIdentifier;
128 throw new ExtensionError( 170 throw new ExtensionError(
129 'Extensions to $id must be a RequestHandlerFactory'); 171 'Extensions to $id must be a RequestHandlerFactory');
130 } 172 }
131 } 173 }
132 174
133 /** 175 /**
134 * Validate the given extension by throwing an [ExtensionError] if it is not a 176 * Validate the given extension by throwing an [ExtensionError] if it is not a
135 * valid fix contributor. 177 * valid fix contributor.
136 */ 178 */
137 void _validateFixContributorExtension(Object extension) { 179 void _validateFixContributorExtension(Object extension) {
138 if (extension is! FixContributor) { 180 if (extension is! FixContributor) {
139 String id = domainExtensionPoint.uniqueIdentifier; 181 String id = fixContributorExtensionPoint.uniqueIdentifier;
140 throw new ExtensionError('Extensions to $id must be a FixContributor'); 182 throw new ExtensionError('Extensions to $id must be a FixContributor');
141 } 183 }
142 } 184 }
143 } 185 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/edit/edit_domain.dart ('k') | pkg/analysis_server/lib/src/services/correction/assist.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698