Chromium Code Reviews| 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'; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 * [AnalysisServer] instances to improve performance. | 27 * [AnalysisServer] instances to improve performance. |
| 28 */ | 28 */ |
| 29 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; | 29 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; |
| 30 | 30 |
| 31 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { | 31 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { |
| 32 final AnalysisServer analysisServer; | 32 final AnalysisServer analysisServer; |
| 33 | 33 |
| 34 AnalysisServerContextDirectoryManager(this.analysisServer, ResourceProvider re sourceProvider) | 34 AnalysisServerContextDirectoryManager(this.analysisServer, ResourceProvider re sourceProvider) |
| 35 : super(resourceProvider); | 35 : super(resourceProvider); |
| 36 | 36 |
| 37 void addContext(Folder folder) { | 37 void addContext(Folder folder, File pubspecFile) { |
| 38 PubFolder pubFolder = new PubFolder(analysisServer.defaultSdk, folder); | 38 PubFolder pubFolder = new PubFolder(analysisServer.defaultSdk, folder, pubsp ecFile); |
| 39 analysisServer.folderMap[folder] = pubFolder; | 39 analysisServer.folderMap[folder] = pubFolder; |
| 40 analysisServer.addContextToWorkQueue(pubFolder.context); | 40 analysisServer.addContextToWorkQueue(pubFolder.context); |
| 41 } | 41 } |
| 42 | |
| 43 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | |
| 44 analysisServer.folderMap[contextFolder].context.applyChanges(changeSet); | |
| 45 } | |
| 42 } | 46 } |
| 43 | 47 |
| 44 /** | 48 /** |
| 45 * Instances of the class [AnalysisServer] implement a server that listens on a | 49 * Instances of the class [AnalysisServer] implement a server that listens on a |
| 46 * [CommunicationChannel] for analysis requests and process them. | 50 * [CommunicationChannel] for analysis requests and process them. |
| 47 */ | 51 */ |
| 48 class AnalysisServer { | 52 class AnalysisServer { |
| 49 /** | 53 /** |
| 50 * The name of the parameter whose value is a list of errors. | 54 * The name of the parameter whose value is a list of errors. |
| 51 */ | 55 */ |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 433 |
| 430 | 434 |
| 431 /** | 435 /** |
| 432 * Instances of [PubFolder] represents a [Folder] with a Pub `pubspec.yaml`. | 436 * Instances of [PubFolder] represents a [Folder] with a Pub `pubspec.yaml`. |
| 433 * | 437 * |
| 434 * TODO(scheglov) implement complete projects/contexts semantics. | 438 * TODO(scheglov) implement complete projects/contexts semantics. |
| 435 * | 439 * |
| 436 * This class is intentionally simplified to serve as a base to start working | 440 * This class is intentionally simplified to serve as a base to start working |
| 437 * on services while work on complete semantics is being done in parallel. | 441 * on services while work on complete semantics is being done in parallel. |
| 438 */ | 442 */ |
| 439 class PubFolder { | 443 class PubFolder { |
|
danrubel
2014/05/29 12:07:19
This now represents an analysis root folder which
Paul Berry
2014/05/29 15:22:17
Ok, will do in a future CL.
| |
| 440 /** | 444 /** |
| 441 * The root [Folder] of this [PubFolder]. | 445 * The root [Folder] of this [PubFolder]. |
| 442 */ | 446 */ |
| 443 final Folder _folder; | 447 final Folder _folder; |
| 444 | 448 |
| 445 /** | 449 /** |
| 446 * The `pubspec.yaml` file in [_folder]. | 450 * The `pubspec.yaml` file in [_folder], or null if there isn't one. |
| 447 */ | 451 */ |
| 448 File _pubspecFile; | 452 File _pubspecFile; |
| 449 | 453 |
| 450 /** | 454 /** |
| 451 * The [AnalysisContext] of this [_folder]. | 455 * The [AnalysisContext] of this [_folder]. |
| 452 */ | 456 */ |
| 453 AnalysisContext _context; | 457 AnalysisContext _context; |
| 454 | 458 |
| 455 PubFolder(DartSdk sdk, this._folder) { | 459 PubFolder(DartSdk sdk, this._folder, this._pubspecFile) { |
| 456 // prepare pubspec.yaml | |
| 457 _pubspecFile = _folder.getChild('pubspec.yaml'); | |
| 458 if (!_pubspecFile.exists) { | |
| 459 throw new ArgumentError('$_pubspecFile does not exist'); | |
| 460 } | |
| 461 // create AnalysisContext | 460 // create AnalysisContext |
| 462 _context = AnalysisEngine.instance.createAnalysisContext(); | 461 _context = AnalysisEngine.instance.createAnalysisContext(); |
| 463 // TODO(scheglov) replace FileUriResolver with an Resource based resolver | 462 // TODO(scheglov) replace FileUriResolver with an Resource based resolver |
| 464 // TODO(scheglov) create packages resolver | 463 // TODO(scheglov) create packages resolver |
| 465 _context.sourceFactory = new SourceFactory([ | 464 _context.sourceFactory = new SourceFactory([ |
| 466 new DartUriResolver(sdk), | 465 new DartUriResolver(sdk), |
| 467 new FileUriResolver(), | 466 new FileUriResolver(), |
| 468 // new PackageUriResolver(), | 467 // new PackageUriResolver(), |
| 469 ]); | 468 ]); |
| 470 // add folder files | |
| 471 { | |
| 472 ChangeSet changeSet = new ChangeSet(); | |
| 473 _addSourceFiles(changeSet, _folder); | |
| 474 _context.applyChanges(changeSet); | |
| 475 } | |
| 476 } | 469 } |
| 477 | 470 |
| 478 /** | 471 /** |
| 479 * Return the [AnalysisContext] of this folder. | 472 * Return the [AnalysisContext] of this folder. |
| 480 */ | 473 */ |
| 481 AnalysisContext get context => _context; | 474 AnalysisContext get context => _context; |
| 482 | |
| 483 /** | |
| 484 * Resursively adds all Dart and HTML files to the [changeSet]. | |
| 485 */ | |
| 486 static void _addSourceFiles(ChangeSet changeSet, Folder folder) { | |
| 487 List<Resource> children = folder.getChildren(); | |
| 488 for (Resource child in children) { | |
| 489 if (child is File) { | |
| 490 String fileName = child.shortName; | |
| 491 if (AnalysisEngine.isDartFileName(fileName) | |
| 492 || AnalysisEngine.isHtmlFileName(fileName)) { | |
| 493 Source source = child.createSource(UriKind.FILE_URI); | |
| 494 changeSet.addedSource(source); | |
| 495 } | |
| 496 } else if (child is Folder) { | |
| 497 _addSourceFiles(changeSet, child); | |
| 498 } | |
| 499 } | |
| 500 } | |
| 501 } | 475 } |
| 502 | 476 |
| 503 | 477 |
| 504 /** | 478 /** |
| 505 * An enumeration of the services provided by the server domain. | 479 * An enumeration of the services provided by the server domain. |
| 506 */ | 480 */ |
| 507 class ServerService extends Enum2<ServerService> { | 481 class ServerService extends Enum2<ServerService> { |
| 508 static const ServerService STATUS = const ServerService('STATUS', 0); | 482 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 509 | 483 |
| 510 static const List<ServerService> VALUES = const [STATUS]; | 484 static const List<ServerService> VALUES = const [STATUS]; |
| 511 | 485 |
| 512 const ServerService(String name, int ordinal) : super(name, ordinal); | 486 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 513 } | 487 } |
| OLD | NEW |