OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:core'; | 6 import 'dart:core'; |
7 | 7 |
8 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; | 8 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; |
9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/computer/computer_hover.dart'; | 10 import 'package:analysis_server/src/computer/computer_hover.dart'; |
11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
12 import 'package:analysis_server/src/context_manager.dart'; | 12 import 'package:analysis_server/src/context_manager.dart'; |
13 import 'package:analysis_server/src/domain_abstract.dart'; | 13 import 'package:analysis_server/src/domain_abstract.dart'; |
14 import 'package:analysis_server/src/domains/analysis/navigation.dart'; | 14 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
15 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; | 15 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; |
16 import 'package:analysis_server/src/operation/operation_analysis.dart' | 16 import 'package:analysis_server/src/operation/operation_analysis.dart' |
17 show NavigationOperation, OccurrencesOperation; | 17 show NavigationOperation, OccurrencesOperation; |
18 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | 18 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
19 import 'package:analysis_server/src/plugin/request_converter.dart'; | 19 import 'package:analysis_server/src/plugin/request_converter.dart'; |
20 import 'package:analysis_server/src/plugin/result_merger.dart'; | 20 import 'package:analysis_server/src/plugin/result_merger.dart'; |
21 import 'package:analysis_server/src/protocol/protocol_internal.dart'; | 21 import 'package:analysis_server/src/protocol/protocol_internal.dart'; |
22 import 'package:analysis_server/src/protocol_server.dart'; | 22 import 'package:analysis_server/src/protocol_server.dart'; |
23 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; | 23 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; |
24 import 'package:analysis_server/src/services/dependencies/reachable_source_colle
ctor.dart'; | |
25 import 'package:analyzer/dart/ast/ast.dart'; | 24 import 'package:analyzer/dart/ast/ast.dart'; |
26 import 'package:analyzer/dart/element/element.dart'; | |
27 import 'package:analyzer/error/error.dart' as engine; | 25 import 'package:analyzer/error/error.dart' as engine; |
28 import 'package:analyzer/exception/exception.dart'; | 26 import 'package:analyzer/exception/exception.dart'; |
29 import 'package:analyzer/file_system/file_system.dart'; | 27 import 'package:analyzer/file_system/file_system.dart'; |
30 import 'package:analyzer/src/dart/analysis/driver.dart'; | 28 import 'package:analyzer/src/dart/analysis/driver.dart'; |
31 import 'package:analyzer/src/generated/engine.dart' as engine; | 29 import 'package:analyzer/src/generated/engine.dart' as engine; |
32 import 'package:analyzer/src/generated/source.dart'; | 30 import 'package:analyzer/src/generated/source.dart'; |
33 import 'package:analyzer/task/model.dart' show ResultDescriptor; | 31 import 'package:analyzer/task/model.dart' show ResultDescriptor; |
34 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; | 32 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; |
35 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 33 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
36 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; | 34 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; |
(...skipping 22 matching lines...) Expand all Loading... |
59 if (lineInfo == null) { | 57 if (lineInfo == null) { |
60 server.sendResponse(new Response.getErrorsInvalidFile(request)); | 58 server.sendResponse(new Response.getErrorsInvalidFile(request)); |
61 } else { | 59 } else { |
62 List<AnalysisError> protocolErrors = | 60 List<AnalysisError> protocolErrors = |
63 doAnalysisError_listFromEngine(analysisOptions, lineInfo, errors); | 61 doAnalysisError_listFromEngine(analysisOptions, lineInfo, errors); |
64 server.sendResponse( | 62 server.sendResponse( |
65 new AnalysisGetErrorsResult(protocolErrors).toResponse(request.id)); | 63 new AnalysisGetErrorsResult(protocolErrors).toResponse(request.id)); |
66 } | 64 } |
67 } | 65 } |
68 | 66 |
69 if (server.options.enableNewAnalysisDriver) { | 67 AnalysisResult result = await server.getAnalysisResult(file); |
70 var result = await server.getAnalysisResult(file); | |
71 | 68 |
72 if (server.onResultErrorSupplementor != null) { | 69 if (server.onResultErrorSupplementor != null) { |
73 if (result != null) { | 70 if (result != null) { |
74 await server.onResultErrorSupplementor(file, result.errors); | 71 await server.onResultErrorSupplementor(file, result.errors); |
75 } else { | 72 } else { |
76 server.onNoAnalysisResult(file, send); | 73 server.onNoAnalysisResult(file, send); |
77 return; | 74 return; |
78 } | |
79 } | 75 } |
80 | |
81 send(result?.driver?.analysisOptions, result?.lineInfo, result?.errors); | |
82 return; | |
83 } | 76 } |
84 | 77 |
85 Future<AnalysisDoneReason> completionFuture = | 78 send(result?.driver?.analysisOptions, result?.lineInfo, result?.errors); |
86 server.onFileAnalysisComplete(file); | |
87 if (completionFuture == null) { | |
88 server.sendResponse(new Response.getErrorsInvalidFile(request)); | |
89 } | |
90 completionFuture.then((AnalysisDoneReason reason) async { | |
91 switch (reason) { | |
92 case AnalysisDoneReason.COMPLETE: | |
93 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | |
94 if (errorInfo == null) { | |
95 server.sendResponse(new Response.getErrorsInvalidFile(request)); | |
96 } else { | |
97 engine.AnalysisContext context = server.getAnalysisContext(file); | |
98 send(context.analysisOptions, errorInfo.lineInfo, errorInfo.errors); | |
99 } | |
100 break; | |
101 case AnalysisDoneReason.CONTEXT_REMOVED: | |
102 // The active contexts have changed, so try again. | |
103 await getErrors(request); | |
104 break; | |
105 } | |
106 }); | |
107 } | 79 } |
108 | 80 |
109 /** | 81 /** |
110 * Implement the `analysis.getHover` request. | 82 * Implement the `analysis.getHover` request. |
111 */ | 83 */ |
112 Future<Null> getHover(Request request) async { | 84 Future<Null> getHover(Request request) async { |
113 var params = new AnalysisGetHoverParams.fromRequest(request); | 85 var params = new AnalysisGetHoverParams.fromRequest(request); |
114 | 86 |
115 // Prepare the resolved units. | 87 // Prepare the resolved units. |
116 CompilationUnit unit; | 88 AnalysisResult result = await server.getAnalysisResult(params.file); |
117 if (server.options.enableNewAnalysisDriver) { | 89 CompilationUnit unit = result?.unit; |
118 AnalysisResult result = await server.getAnalysisResult(params.file); | |
119 unit = result?.unit; | |
120 } else { | |
121 unit = await server.getResolvedCompilationUnit(params.file); | |
122 } | |
123 | 90 |
124 // Prepare the hovers. | 91 // Prepare the hovers. |
125 List<HoverInformation> hovers = <HoverInformation>[]; | 92 List<HoverInformation> hovers = <HoverInformation>[]; |
126 if (unit != null) { | 93 if (unit != null) { |
127 HoverInformation hoverInformation = | 94 HoverInformation hoverInformation = |
128 new DartUnitHoverComputer(unit, params.offset).compute(); | 95 new DartUnitHoverComputer(unit, params.offset).compute(); |
129 if (hoverInformation != null) { | 96 if (hoverInformation != null) { |
130 hovers.add(hoverInformation); | 97 hovers.add(hoverInformation); |
131 } | 98 } |
132 } | 99 } |
(...skipping 23 matching lines...) Expand all Loading... |
156 | 123 |
157 /** | 124 /** |
158 * Implement the `analysis.getNavigation` request. | 125 * Implement the `analysis.getNavigation` request. |
159 */ | 126 */ |
160 Future<Null> getNavigation(Request request) async { | 127 Future<Null> getNavigation(Request request) async { |
161 var params = new AnalysisGetNavigationParams.fromRequest(request); | 128 var params = new AnalysisGetNavigationParams.fromRequest(request); |
162 String file = params.file; | 129 String file = params.file; |
163 int offset = params.offset; | 130 int offset = params.offset; |
164 int length = params.length; | 131 int length = params.length; |
165 | 132 |
166 if (server.options.enableNewAnalysisDriver) { | 133 AnalysisDriver driver = server.getAnalysisDriver(file); |
167 AnalysisDriver driver = server.getAnalysisDriver(file); | 134 if (driver == null) { |
168 if (driver == null) { | 135 server.sendResponse(new Response.getNavigationInvalidFile(request)); |
169 server.sendResponse(new Response.getNavigationInvalidFile(request)); | 136 } else { |
170 } else { | 137 // |
171 // | 138 // Allow plugins to start computing navigation data. |
172 // Allow plugins to start computing navigation data. | 139 // |
173 // | 140 plugin.AnalysisGetNavigationParams requestParams = |
174 plugin.AnalysisGetNavigationParams requestParams = | 141 new plugin.AnalysisGetNavigationParams(file, offset, length); |
175 new plugin.AnalysisGetNavigationParams(file, offset, length); | 142 Map<PluginInfo, Future<plugin.Response>> pluginFutures = server |
176 Map<PluginInfo, Future<plugin.Response>> pluginFutures = server | 143 .pluginManager |
177 .pluginManager | 144 .broadcastRequest(requestParams, contextRoot: driver.contextRoot); |
178 .broadcastRequest(requestParams, contextRoot: driver.contextRoot); | 145 // |
179 // | 146 // Compute navigation data generated by server. |
180 // Compute navigation data generated by server. | 147 // |
181 // | 148 List<AnalysisNavigationParams> allResults = <AnalysisNavigationParams>[]; |
182 List<AnalysisNavigationParams> allResults = | 149 AnalysisResult result = await server.getAnalysisResult(file); |
183 <AnalysisNavigationParams>[]; | 150 CompilationUnit unit = result?.unit; |
184 AnalysisResult result = await server.getAnalysisResult(file); | 151 if (unit != null && result.exists) { |
185 CompilationUnit unit = result?.unit; | 152 NavigationCollectorImpl collector = new NavigationCollectorImpl(); |
186 if (unit != null && result.exists) { | 153 computeDartNavigation(collector, unit, offset, length); |
187 NavigationCollectorImpl collector = new NavigationCollectorImpl(); | 154 collector.createRegions(); |
188 computeDartNavigation(collector, unit, offset, length); | 155 allResults.add(new AnalysisNavigationParams( |
189 collector.createRegions(); | 156 file, collector.regions, collector.targets, collector.files)); |
| 157 } |
| 158 // |
| 159 // Add the navigation data produced by plugins to the server-generated |
| 160 // navigation data. |
| 161 // |
| 162 if (pluginFutures != null) { |
| 163 List<plugin.Response> responses = await waitForResponses(pluginFutures, |
| 164 requestParameters: requestParams); |
| 165 for (plugin.Response response in responses) { |
| 166 plugin.AnalysisGetNavigationResult result = |
| 167 new plugin.AnalysisGetNavigationResult.fromResponse(response); |
190 allResults.add(new AnalysisNavigationParams( | 168 allResults.add(new AnalysisNavigationParams( |
191 file, collector.regions, collector.targets, collector.files)); | 169 file, result.regions, result.targets, result.files)); |
192 } | |
193 // | |
194 // Add the navigation data produced by plugins to the server-generated | |
195 // navigation data. | |
196 // | |
197 if (pluginFutures != null) { | |
198 List<plugin.Response> responses = await waitForResponses( | |
199 pluginFutures, | |
200 requestParameters: requestParams); | |
201 for (plugin.Response response in responses) { | |
202 plugin.AnalysisGetNavigationResult result = | |
203 new plugin.AnalysisGetNavigationResult.fromResponse(response); | |
204 allResults.add(new AnalysisNavigationParams( | |
205 file, result.regions, result.targets, result.files)); | |
206 } | |
207 } | |
208 // | |
209 // Return the result. | |
210 // | |
211 ResultMerger merger = new ResultMerger(); | |
212 AnalysisNavigationParams mergedResults = | |
213 merger.mergeNavigation(allResults); | |
214 if (mergedResults == null) { | |
215 server.sendResponse(new AnalysisGetNavigationResult( | |
216 <String>[], <NavigationTarget>[], <NavigationRegion>[]) | |
217 .toResponse(request.id)); | |
218 } else { | |
219 server.sendResponse(new AnalysisGetNavigationResult( | |
220 mergedResults.files, | |
221 mergedResults.targets, | |
222 mergedResults.regions) | |
223 .toResponse(request.id)); | |
224 } | 170 } |
225 } | 171 } |
226 return; | 172 // |
| 173 // Return the result. |
| 174 // |
| 175 ResultMerger merger = new ResultMerger(); |
| 176 AnalysisNavigationParams mergedResults = |
| 177 merger.mergeNavigation(allResults); |
| 178 if (mergedResults == null) { |
| 179 server.sendResponse(new AnalysisGetNavigationResult( |
| 180 <String>[], <NavigationTarget>[], <NavigationRegion>[]) |
| 181 .toResponse(request.id)); |
| 182 } else { |
| 183 server.sendResponse(new AnalysisGetNavigationResult(mergedResults.files, |
| 184 mergedResults.targets, mergedResults.regions) |
| 185 .toResponse(request.id)); |
| 186 } |
227 } | 187 } |
228 | |
229 Future<AnalysisDoneReason> analysisFuture = | |
230 server.onFileAnalysisComplete(file); | |
231 if (analysisFuture == null) { | |
232 server.sendResponse(new Response.getNavigationInvalidFile(request)); | |
233 return; | |
234 } | |
235 analysisFuture.then((AnalysisDoneReason reason) async { | |
236 switch (reason) { | |
237 case AnalysisDoneReason.COMPLETE: | |
238 CompilationUnit unit = await server.getResolvedCompilationUnit(file); | |
239 if (unit == null) { | |
240 server.sendResponse(new Response.getNavigationInvalidFile(request)); | |
241 } else { | |
242 CompilationUnitElement unitElement = unit.element; | |
243 NavigationCollectorImpl collector = computeNavigation( | |
244 server, | |
245 unitElement.context, | |
246 unitElement.source, | |
247 params.offset, | |
248 params.length); | |
249 server.sendResponse(new AnalysisGetNavigationResult( | |
250 collector.files, collector.targets, collector.regions) | |
251 .toResponse(request.id)); | |
252 } | |
253 break; | |
254 case AnalysisDoneReason.CONTEXT_REMOVED: | |
255 // The active contexts have changed, so try again. | |
256 await getNavigation(request); | |
257 break; | |
258 } | |
259 }); | |
260 } | 188 } |
261 | 189 |
262 /** | 190 /** |
263 * Implement the `analysis.getReachableSources` request. | 191 * Implement the `analysis.getReachableSources` request. |
264 */ | 192 */ |
265 Response getReachableSources(Request request) { | 193 Response getReachableSources(Request request) { |
266 AnalysisGetReachableSourcesParams params = | 194 return new Response.unsupportedFeature(request.id, |
267 new AnalysisGetReachableSourcesParams.fromRequest(request); | 195 'Please contact the Dart analyzer team if you need this request.'); |
268 ContextSourcePair pair = server.getContextSourcePair(params.file); | 196 // AnalysisGetReachableSourcesParams params = |
269 if (pair.context == null || pair.source == null) { | 197 // new AnalysisGetReachableSourcesParams.fromRequest(request); |
270 return new Response.getReachableSourcesInvalidFile(request); | 198 // ContextSourcePair pair = server.getContextSourcePair(params.file); |
271 } | 199 // if (pair.context == null || pair.source == null) { |
272 Map<String, List<String>> sources = | 200 // return new Response.getReachableSourcesInvalidFile(request); |
273 new ReachableSourceCollector(pair.source, pair.context) | 201 // } |
274 .collectSources(); | 202 // Map<String, List<String>> sources = |
275 return new AnalysisGetReachableSourcesResult(sources) | 203 // new ReachableSourceCollector(pair.source, pair.context) |
276 .toResponse(request.id); | 204 // .collectSources(); |
| 205 // return new AnalysisGetReachableSourcesResult(sources) |
| 206 // .toResponse(request.id); |
277 } | 207 } |
278 | 208 |
279 @override | 209 @override |
280 Response handleRequest(Request request) { | 210 Response handleRequest(Request request) { |
281 try { | 211 try { |
282 String requestName = request.method; | 212 String requestName = request.method; |
283 if (requestName == ANALYSIS_GET_ERRORS) { | 213 if (requestName == ANALYSIS_GET_ERRORS) { |
284 getErrors(request); | 214 getErrors(request); |
285 return Response.DELAYED_RESPONSE; | 215 return Response.DELAYED_RESPONSE; |
286 } else if (requestName == ANALYSIS_GET_HOVER) { | 216 } else if (requestName == ANALYSIS_GET_HOVER) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 context.onResultChanged(descriptor).listen((result) { | 464 context.onResultChanged(descriptor).listen((result) { |
535 StreamController<engine.ResultChangedEvent> controller = | 465 StreamController<engine.ResultChangedEvent> controller = |
536 controllers[result.descriptor]; | 466 controllers[result.descriptor]; |
537 if (controller != null) { | 467 if (controller != null) { |
538 controller.add(result); | 468 controller.add(result); |
539 } | 469 } |
540 }); | 470 }); |
541 } | 471 } |
542 } | 472 } |
543 } | 473 } |
OLD | NEW |