| 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 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/analysis_logger.dart'; | 10 import 'package:analysis_server/src/analysis_logger.dart'; |
| 11 import 'package:analysis_server/src/channel.dart'; | 11 import 'package:analysis_server/src/channel.dart'; |
| 12 import 'package:analysis_server/src/constants.dart'; | 12 import 'package:analysis_server/src/constants.dart'; |
| 13 import 'package:analysis_server/src/context_directory_manager.dart'; | 13 import 'package:analysis_server/src/context_directory_manager.dart'; |
| 14 import 'package:analysis_server/src/domain_analysis.dart'; | 14 import 'package:analysis_server/src/domain_analysis.dart'; |
| 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 16 import 'package:analysis_server/src/operation/operation.dart'; | 16 import 'package:analysis_server/src/operation/operation.dart'; |
| 17 import 'package:analysis_server/src/operation/operation_queue.dart'; | 17 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 18 import 'package:analysis_server/src/package_map_provider.dart'; | 18 import 'package:analysis_server/src/package_map_provider.dart'; |
| 19 import 'package:analysis_server/src/package_uri_resolver.dart'; | 19 import 'package:analysis_server/src/package_uri_resolver.dart'; |
| 20 import 'package:analysis_server/src/protocol.dart'; | 20 import 'package:analysis_server/src/protocol.dart'; |
| 21 import 'package:analysis_server/src/resource.dart'; | 21 import 'package:analysis_server/src/resource.dart'; |
| 22 import 'package:analyzer/src/generated/ast.dart'; | 22 import 'package:analyzer/src/generated/ast.dart'; |
| 23 import 'package:analyzer/src/generated/engine.dart'; | 23 import 'package:analyzer/src/generated/engine.dart'; |
| 24 import 'package:analyzer/src/generated/error.dart'; | 24 import 'package:analyzer/src/generated/error.dart'; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/src/generated/sdk.dart'; | 26 import 'package:analyzer/src/generated/sdk.dart'; |
| 27 import 'package:analyzer/src/generated/sdk_io.dart'; | 27 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 28 import 'package:analyzer/src/generated/source_io.dart'; | 28 import 'package:analyzer/src/generated/source_io.dart'; |
| 29 import 'package:analyzer/src/generated/java_engine.dart'; | 29 import 'package:analyzer/src/generated/java_engine.dart'; |
| 30 import 'package:analyzer/src/generated/index.dart'; |
| 30 | 31 |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * An instance of [DirectoryBasedDartSdk] that is shared between | 34 * An instance of [DirectoryBasedDartSdk] that is shared between |
| 34 * [AnalysisServer] instances to improve performance. | 35 * [AnalysisServer] instances to improve performance. |
| 35 */ | 36 */ |
| 36 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; | 37 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; |
| 37 | 38 |
| 38 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { | 39 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { |
| 39 final AnalysisServer analysisServer; | 40 final AnalysisServer analysisServer; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 * [CommunicationChannel] for analysis requests and process them. | 77 * [CommunicationChannel] for analysis requests and process them. |
| 77 */ | 78 */ |
| 78 class AnalysisServer { | 79 class AnalysisServer { |
| 79 /** | 80 /** |
| 80 * The channel from which requests are received and to which responses should | 81 * The channel from which requests are received and to which responses should |
| 81 * be sent. | 82 * be sent. |
| 82 */ | 83 */ |
| 83 final ServerCommunicationChannel channel; | 84 final ServerCommunicationChannel channel; |
| 84 | 85 |
| 85 /** | 86 /** |
| 87 * The [Index] for this server. |
| 88 */ |
| 89 final Index index; |
| 90 |
| 91 /** |
| 86 * [ContextDirectoryManager] which handles the mapping from analysis roots | 92 * [ContextDirectoryManager] which handles the mapping from analysis roots |
| 87 * to context directories. | 93 * to context directories. |
| 88 */ | 94 */ |
| 89 AnalysisServerContextDirectoryManager contextDirectoryManager; | 95 AnalysisServerContextDirectoryManager contextDirectoryManager; |
| 90 | 96 |
| 91 /** | 97 /** |
| 92 * Provider which is used to determine the mapping from package name to | 98 * Provider which is used to determine the mapping from package name to |
| 93 * package folder. | 99 * package folder. |
| 94 */ | 100 */ |
| 95 final PackageMapProvider packageMapProvider; | 101 final PackageMapProvider packageMapProvider; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 /** | 154 /** |
| 149 * Initialize a newly created server to receive requests from and send | 155 * Initialize a newly created server to receive requests from and send |
| 150 * responses to the given [channel]. | 156 * responses to the given [channel]. |
| 151 * | 157 * |
| 152 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 158 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 153 * propagated up the call stack. The default is true to allow analysis | 159 * propagated up the call stack. The default is true to allow analysis |
| 154 * exceptions to show up in unit tests, but it should be set to false when | 160 * exceptions to show up in unit tests, but it should be set to false when |
| 155 * running a full analysis server. | 161 * running a full analysis server. |
| 156 */ | 162 */ |
| 157 AnalysisServer(this.channel, ResourceProvider resourceProvider, | 163 AnalysisServer(this.channel, ResourceProvider resourceProvider, |
| 158 this.packageMapProvider, {this.rethrowExceptions: true}) { | 164 this.packageMapProvider, this.index, {this.rethrowExceptions: true}) { |
| 159 operationQueue = new ServerOperationQueue(this); | 165 operationQueue = new ServerOperationQueue(this); |
| 160 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re
sourceProvider); | 166 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re
sourceProvider); |
| 161 AnalysisEngine.instance.logger = new AnalysisLogger(); | 167 AnalysisEngine.instance.logger = new AnalysisLogger(); |
| 162 running = true; | 168 running = true; |
| 163 Notification notification = new Notification(SERVER_CONNECTED); | 169 Notification notification = new Notification(SERVER_CONNECTED); |
| 164 channel.sendNotification(notification); | 170 channel.sendNotification(notification); |
| 165 channel.listen(handleRequest, onDone: done, onError: error); | 171 channel.listen(handleRequest, onDone: done, onError: error); |
| 166 } | 172 } |
| 167 | 173 |
| 168 /** | 174 /** |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 * operations execution. | 262 * operations execution. |
| 257 */ | 263 */ |
| 258 void addOperation(ServerOperation operation) { | 264 void addOperation(ServerOperation operation) { |
| 259 operationQueue.add(operation); | 265 operationQueue.add(operation); |
| 260 } | 266 } |
| 261 | 267 |
| 262 /** | 268 /** |
| 263 * The socket from which requests are being read has been closed. | 269 * The socket from which requests are being read has been closed. |
| 264 */ | 270 */ |
| 265 void done() { | 271 void done() { |
| 272 index.stop(); |
| 266 running = false; | 273 running = false; |
| 267 } | 274 } |
| 268 | 275 |
| 269 /** | 276 /** |
| 270 * There was an error related to the socket from which requests are being | 277 * There was an error related to the socket from which requests are being |
| 271 * read. | 278 * read. |
| 272 */ | 279 */ |
| 273 void error(argument) { | 280 void error(argument) { |
| 274 running = false; | 281 running = false; |
| 275 } | 282 } |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 * The [AnalysisContext] of this [_folder]. | 594 * The [AnalysisContext] of this [_folder]. |
| 588 */ | 595 */ |
| 589 AnalysisContext _context; | 596 AnalysisContext _context; |
| 590 | 597 |
| 591 ContextDirectory(DartSdk sdk, this._resourceProvider, this._folder, | 598 ContextDirectory(DartSdk sdk, this._resourceProvider, this._folder, |
| 592 Map<String, List<Folder>> packageMap) { | 599 Map<String, List<Folder>> packageMap) { |
| 593 // create AnalysisContext | 600 // create AnalysisContext |
| 594 _context = AnalysisEngine.instance.createAnalysisContext(); | 601 _context = AnalysisEngine.instance.createAnalysisContext(); |
| 595 // TODO(scheglov) replace FileUriResolver with an Resource based resolver | 602 // TODO(scheglov) replace FileUriResolver with an Resource based resolver |
| 596 List<UriResolver> resolvers = <UriResolver>[new DartUriResolver(sdk), | 603 List<UriResolver> resolvers = <UriResolver>[new DartUriResolver(sdk), |
| 597 new FileUriResolver(), | 604 new ResourceUriResolver(_resourceProvider), |
| 598 ]; | 605 ]; |
| 599 if (packageMap != null) { | 606 if (packageMap != null) { |
| 600 resolvers.add(new PackageMapUriResolver(_resourceProvider, packageMap)); | 607 resolvers.add(new PackageMapUriResolver(_resourceProvider, packageMap)); |
| 601 } | 608 } |
| 602 _context.sourceFactory = new SourceFactory(resolvers); | 609 _context.sourceFactory = new SourceFactory(resolvers); |
| 603 } | 610 } |
| 604 | 611 |
| 605 /** | 612 /** |
| 606 * Return the [AnalysisContext] of this folder. | 613 * Return the [AnalysisContext] of this folder. |
| 607 */ | 614 */ |
| 608 AnalysisContext get context => _context; | 615 AnalysisContext get context => _context; |
| 609 } | 616 } |
| 610 | 617 |
| 611 typedef void OptionUpdater(AnalysisOptionsImpl options); | 618 typedef void OptionUpdater(AnalysisOptionsImpl options); |
| 612 | 619 |
| 613 /** | 620 /** |
| 614 * An enumeration of the services provided by the server domain. | 621 * An enumeration of the services provided by the server domain. |
| 615 */ | 622 */ |
| 616 class ServerService extends Enum2<ServerService> { | 623 class ServerService extends Enum2<ServerService> { |
| 617 static const ServerService STATUS = const ServerService('STATUS', 0); | 624 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 618 | 625 |
| 619 static const List<ServerService> VALUES = const [STATUS]; | 626 static const List<ServerService> VALUES = const [STATUS]; |
| 620 | 627 |
| 621 const ServerService(String name, int ordinal) : super(name, ordinal); | 628 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 622 } | 629 } |
| OLD | NEW |