| 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 library domain.analysis; | 5 library domain.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 | 9 |
| 10 import 'package:analysis_server/analysis/analysis_domain.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/computer/computer_hover.dart'; | 12 import 'package:analysis_server/src/computer/computer_hover.dart'; |
| 12 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
| 14 import 'package:analysis_server/src/context_manager.dart'; |
| 13 import 'package:analysis_server/src/domains/analysis/navigation.dart'; | 15 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
| 16 import 'package:analysis_server/src/operation/operation_analysis.dart' |
| 17 show sendAnalysisNotificationNavigation; |
| 14 import 'package:analysis_server/src/protocol_server.dart'; | 18 import 'package:analysis_server/src/protocol_server.dart'; |
| 15 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; | 19 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; |
| 16 import 'package:analyzer/file_system/file_system.dart'; | 20 import 'package:analyzer/file_system/file_system.dart'; |
| 17 import 'package:analyzer/src/generated/ast.dart'; | 21 import 'package:analyzer/src/generated/ast.dart'; |
| 18 import 'package:analyzer/src/generated/element.dart'; | 22 import 'package:analyzer/src/generated/element.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart' as engine; | 23 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 24 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 25 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/task/model.dart' show ResultDescriptor; |
| 20 | 27 |
| 21 /** | 28 /** |
| 22 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 29 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
| 23 * that handles requests in the `analysis` domain. | 30 * that handles requests in the `analysis` domain. |
| 24 */ | 31 */ |
| 25 class AnalysisDomainHandler implements RequestHandler { | 32 class AnalysisDomainHandler implements RequestHandler { |
| 26 /** | 33 /** |
| 27 * The analysis server that is using this handler to process requests. | 34 * The analysis server that is using this handler to process requests. |
| 28 */ | 35 */ |
| 29 final AnalysisServer server; | 36 final AnalysisServer server; |
| 30 | 37 |
| 31 /** | 38 /** |
| 32 * Initialize a newly created handler to handle requests for the given [server
]. | 39 * Initialize a newly created handler to handle requests for the given [server
]. |
| 33 */ | 40 */ |
| 34 AnalysisDomainHandler(this.server); | 41 AnalysisDomainHandler(this.server) { |
| 42 _callAnalysisDomainReceivers(); |
| 43 } |
| 35 | 44 |
| 36 /** | 45 /** |
| 37 * Implement the `analysis.getErrors` request. | 46 * Implement the `analysis.getErrors` request. |
| 38 */ | 47 */ |
| 39 Response getErrors(Request request) { | 48 Response getErrors(Request request) { |
| 40 String file = new AnalysisGetErrorsParams.fromRequest(request).file; | 49 String file = new AnalysisGetErrorsParams.fromRequest(request).file; |
| 41 Future<AnalysisDoneReason> completionFuture = | 50 Future<AnalysisDoneReason> completionFuture = |
| 42 server.onFileAnalysisComplete(file); | 51 server.onFileAnalysisComplete(file); |
| 43 if (completionFuture == null) { | 52 if (completionFuture == null) { |
| 44 return new Response.getErrorsInvalidFile(request); | 53 return new Response.getErrorsInvalidFile(request); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 }); | 292 }); |
| 284 } | 293 } |
| 285 if (newOptions.enableSuperMixins != null) { | 294 if (newOptions.enableSuperMixins != null) { |
| 286 updaters.add((engine.AnalysisOptionsImpl options) { | 295 updaters.add((engine.AnalysisOptionsImpl options) { |
| 287 options.enableSuperMixins = newOptions.enableSuperMixins; | 296 options.enableSuperMixins = newOptions.enableSuperMixins; |
| 288 }); | 297 }); |
| 289 } | 298 } |
| 290 server.updateOptions(updaters); | 299 server.updateOptions(updaters); |
| 291 return new AnalysisUpdateOptionsResult().toResponse(request.id); | 300 return new AnalysisUpdateOptionsResult().toResponse(request.id); |
| 292 } | 301 } |
| 302 |
| 303 /** |
| 304 * Call all the registered [SetAnalysisDomain] functions. |
| 305 */ |
| 306 void _callAnalysisDomainReceivers() { |
| 307 AnalysisDomain analysisDomain = new AnalysisDomainImpl(server); |
| 308 for (SetAnalysisDomain function |
| 309 in server.serverPlugin.setAnalysisDomainFunctions) { |
| 310 try { |
| 311 function(analysisDomain); |
| 312 } catch (exception, stackTrace) { |
| 313 engine.AnalysisEngine.instance.logger.logError( |
| 314 'Exception from analysis domain receiver: ${function.runtimeType}', |
| 315 new CaughtException(exception, stackTrace)); |
| 316 } |
| 317 } |
| 318 } |
| 293 } | 319 } |
| 320 |
| 321 /** |
| 322 * An implementation of [AnalysisDomain] for [AnalysisServer]. |
| 323 */ |
| 324 class AnalysisDomainImpl implements AnalysisDomain { |
| 325 final AnalysisServer server; |
| 326 |
| 327 final Map<ResultDescriptor, |
| 328 StreamController<engine.ComputedResult>> controllers = |
| 329 <ResultDescriptor, StreamController<engine.ComputedResult>>{}; |
| 330 |
| 331 AnalysisDomainImpl(this.server) { |
| 332 server.onContextsChanged.listen((ContextsChangedEvent event) { |
| 333 event.added.forEach(_subscribeForContext); |
| 334 }); |
| 335 } |
| 336 |
| 337 @override |
| 338 Stream<engine.ComputedResult> onResultComputed(ResultDescriptor descriptor) { |
| 339 Stream<engine.ComputedResult> stream = controllers |
| 340 .putIfAbsent(descriptor, |
| 341 () => new StreamController<engine.ComputedResult>.broadcast()) |
| 342 .stream; |
| 343 server.getAnalysisContexts().forEach(_subscribeForContext); |
| 344 return stream; |
| 345 } |
| 346 |
| 347 @override |
| 348 void scheduleNotification( |
| 349 engine.AnalysisContext context, Source source, AnalysisService service) { |
| 350 // TODO(scheglov) schedule, don't do it right now |
| 351 String file = source.fullName; |
| 352 if (server.hasAnalysisSubscription(service, file)) { |
| 353 if (service == AnalysisService.NAVIGATION) { |
| 354 sendAnalysisNotificationNavigation(server, context, source); |
| 355 } |
| 356 } |
| 357 } |
| 358 |
| 359 void _subscribeForContext(engine.AnalysisContext context) { |
| 360 for (ResultDescriptor descriptor in controllers.keys) { |
| 361 context.onResultComputed(descriptor).listen((result) { |
| 362 StreamController<engine.ComputedResult> controller = |
| 363 controllers[result.descriptor]; |
| 364 if (controller != null) { |
| 365 controller.add(result); |
| 366 } |
| 367 }); |
| 368 } |
| 369 } |
| 370 } |
| OLD | NEW |