| 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 analysis.server; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_logger.dart'; | 9 import 'package:analysis_server/src/analysis_logger.dart'; |
| 10 import 'package:analysis_server/src/channel.dart'; | 10 import 'package:analysis_server/src/channel.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/context_directory_manager.dart'; | 12 import 'package:analysis_server/src/context_directory_manager.dart'; |
| 13 import 'package:analysis_server/src/domain_analysis.dart'; | 13 import 'package:analysis_server/src/domain_analysis.dart'; |
| 14 import 'package:analysis_server/src/protocol.dart'; | 14 import 'package:analysis_server/src/protocol.dart'; |
| 15 import 'package:analysis_server/src/resource.dart'; | 15 import 'package:analysis_server/src/resource.dart'; |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 16 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 18 import 'package:analyzer/src/generated/error.dart'; | 18 import 'package:analyzer/src/generated/error.dart'; |
| 19 import 'package:analyzer/src/generated/java_core.dart'; | 19 import 'package:analyzer/src/generated/java_core.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/sdk_io.dart'; | 22 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 23 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:analysis_server/src/computers.dart'; | 24 import 'package:analysis_server/src/computers.dart'; |
| 25 import 'package:analyzer/src/generated/java_engine.dart'; |
| 25 | 26 |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * An instance of [DirectoryBasedDartSdk] that is shared between | 29 * An instance of [DirectoryBasedDartSdk] that is shared between |
| 29 * [AnalysisServer] instances to improve performance. | 30 * [AnalysisServer] instances to improve performance. |
| 30 */ | 31 */ |
| 31 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; | 32 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; |
| 32 | 33 |
| 33 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { | 34 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { |
| 34 final AnalysisServer analysisServer; | 35 final AnalysisServer analysisServer; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 */ | 120 */ |
| 120 Set<ServerService> serverServices = new Set<ServerService>(); | 121 Set<ServerService> serverServices = new Set<ServerService>(); |
| 121 | 122 |
| 122 /** | 123 /** |
| 123 * A table mapping [AnalysisService]s to the file paths for which these | 124 * A table mapping [AnalysisService]s to the file paths for which these |
| 124 * notifications should be sent. | 125 * notifications should be sent. |
| 125 */ | 126 */ |
| 126 Map<AnalysisService, Set<String>> analysisServices = <AnalysisService, Set<Str
ing>>{}; | 127 Map<AnalysisService, Set<String>> analysisServices = <AnalysisService, Set<Str
ing>>{}; |
| 127 | 128 |
| 128 /** | 129 /** |
| 130 * True if any exceptions thrown by analysis should be propagated up the call |
| 131 * stack. |
| 132 */ |
| 133 bool rethrowExceptions; |
| 134 |
| 135 /** |
| 129 * Initialize a newly created server to receive requests from and send | 136 * Initialize a newly created server to receive requests from and send |
| 130 * responses to the given [channel]. | 137 * responses to the given [channel]. |
| 138 * |
| 139 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 140 * propagated up the call stack. The default is true to allow analysis |
| 141 * exceptions to show up in unit tests, but it should be set to false when |
| 142 * running a full analysis server. |
| 131 */ | 143 */ |
| 132 AnalysisServer(this.channel, ResourceProvider resourceProvider) { | 144 AnalysisServer(this.channel, ResourceProvider resourceProvider, |
| 145 {this.rethrowExceptions: true}) { |
| 133 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re
sourceProvider); | 146 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re
sourceProvider); |
| 134 AnalysisEngine.instance.logger = new AnalysisLogger(); | 147 AnalysisEngine.instance.logger = new AnalysisLogger(); |
| 135 running = true; | 148 running = true; |
| 136 Notification notification = new Notification(NOTIFICATION_CONNECTED); | 149 Notification notification = new Notification(NOTIFICATION_CONNECTED); |
| 137 channel.sendNotification(notification); | 150 channel.sendNotification(notification); |
| 138 channel.listen(handleRequest, onDone: done, onError: error); | 151 channel.listen(handleRequest, onDone: done, onError: error); |
| 139 } | 152 } |
| 140 | 153 |
| 141 /** | 154 /** |
| 142 * If [running] is true, add the given [context] to the list of analysis | 155 * If [running] is true, add the given [context] to the list of analysis |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // performAnalysisTask that will be called when the task has been computed | 231 // performAnalysisTask that will be called when the task has been computed |
| 219 // but before it is performed and send notification in the function: | 232 // but before it is performed and send notification in the function: |
| 220 // | 233 // |
| 221 // AnalysisResult result = context.performAnalysisTask((taskDescription) { | 234 // AnalysisResult result = context.performAnalysisTask((taskDescription) { |
| 222 // sendStatusNotification(context.toString(), taskDescription); | 235 // sendStatusNotification(context.toString(), taskDescription); |
| 223 // }); | 236 // }); |
| 224 // | 237 // |
| 225 sendStatusNotification(context.toString()); | 238 sendStatusNotification(context.toString()); |
| 226 AnalysisResult result = context.performAnalysisTask(); | 239 AnalysisResult result = context.performAnalysisTask(); |
| 227 notices = result.changeNotices; | 240 notices = result.changeNotices; |
| 241 } catch (exception, stackTrace) { |
| 242 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); |
| 243 if (rethrowExceptions) { |
| 244 throw new AnalysisException( |
| 245 'Unexpected exception during analysis', |
| 246 new CaughtException(exception, stackTrace)); |
| 247 } |
| 228 } finally { | 248 } finally { |
| 229 if (notices == null) { | 249 if (notices == null) { |
| 230 // Either we have no more work to do for this context, or there was an | 250 // Either we have no more work to do for this context, or there was an |
| 231 // unhandled exception trying to perform the analysis. In either case, | 251 // unhandled exception trying to perform the analysis. In either case, |
| 232 // remove the context form the work queue so we won't try to do more | 252 // remove the context form the work queue so we won't try to do more |
| 233 // analysis on it. | 253 // analysis on it. |
| 234 contextWorkQueue.removeAt(0); | 254 contextWorkQueue.removeAt(0); |
| 235 } else { | 255 } else { |
| 236 sendNotices(notices); | 256 sendNotices(notices); |
| 237 } | 257 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 464 } |
| 445 | 465 |
| 446 /** | 466 /** |
| 447 * Send the given [notification] to the client. | 467 * Send the given [notification] to the client. |
| 448 */ | 468 */ |
| 449 void sendNotification(Notification notification) { | 469 void sendNotification(Notification notification) { |
| 450 channel.sendNotification(notification); | 470 channel.sendNotification(notification); |
| 451 } | 471 } |
| 452 | 472 |
| 453 void _scheduleTask() { | 473 void _scheduleTask() { |
| 454 new Future(performTask).catchError((ex, st) { | 474 new Future(performTask); |
| 455 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); | |
| 456 }); | |
| 457 } | 475 } |
| 458 } | 476 } |
| 459 | 477 |
| 460 | 478 |
| 461 /** | 479 /** |
| 462 * An enumeration of the services provided by the analysis domain. | 480 * An enumeration of the services provided by the analysis domain. |
| 463 */ | 481 */ |
| 464 class AnalysisService extends Enum2<AnalysisService> { | 482 class AnalysisService extends Enum2<AnalysisService> { |
| 465 static const AnalysisService ERRORS = const AnalysisService('ERRORS', 0); | 483 static const AnalysisService ERRORS = const AnalysisService('ERRORS', 0); |
| 466 static const AnalysisService HIGHLIGHTS = const AnalysisService('HIGHLIGHTS',
1); | 484 static const AnalysisService HIGHLIGHTS = const AnalysisService('HIGHLIGHTS',
1); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 /** | 539 /** |
| 522 * An enumeration of the services provided by the server domain. | 540 * An enumeration of the services provided by the server domain. |
| 523 */ | 541 */ |
| 524 class ServerService extends Enum2<ServerService> { | 542 class ServerService extends Enum2<ServerService> { |
| 525 static const ServerService STATUS = const ServerService('STATUS', 0); | 543 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 526 | 544 |
| 527 static const List<ServerService> VALUES = const [STATUS]; | 545 static const List<ServerService> VALUES = const [STATUS]; |
| 528 | 546 |
| 529 const ServerService(String name, int ordinal) : super(name, ordinal); | 547 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 530 } | 548 } |
| OLD | NEW |