| 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 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
| 10 import 'dart:math' show max; | 10 import 'dart:math' show max; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 */ | 288 */ |
| 289 final AnalysisOptionsImpl defaultContextOptions = new AnalysisOptionsImpl(); | 289 final AnalysisOptionsImpl defaultContextOptions = new AnalysisOptionsImpl(); |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * The controller for sending [ContextsChangedEvent]s. | 292 * The controller for sending [ContextsChangedEvent]s. |
| 293 */ | 293 */ |
| 294 StreamController<ContextsChangedEvent> _onContextsChangedController = | 294 StreamController<ContextsChangedEvent> _onContextsChangedController = |
| 295 new StreamController<ContextsChangedEvent>.broadcast(); | 295 new StreamController<ContextsChangedEvent>.broadcast(); |
| 296 | 296 |
| 297 /** | 297 /** |
| 298 * The file resolver provider used to override the way file URI's are |
| 299 * resolved in some contexts. |
| 300 */ |
| 301 ResolverProvider fileResolverProvider; |
| 302 |
| 303 /** |
| 298 * Initialize a newly created server to receive requests from and send | 304 * Initialize a newly created server to receive requests from and send |
| 299 * responses to the given [channel]. | 305 * responses to the given [channel]. |
| 300 * | 306 * |
| 301 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 307 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 302 * propagated up the call stack. The default is true to allow analysis | 308 * propagated up the call stack. The default is true to allow analysis |
| 303 * exceptions to show up in unit tests, but it should be set to false when | 309 * exceptions to show up in unit tests, but it should be set to false when |
| 304 * running a full analysis server. | 310 * running a full analysis server. |
| 305 */ | 311 */ |
| 306 AnalysisServer( | 312 AnalysisServer( |
| 307 this.channel, | 313 this.channel, |
| 308 this.resourceProvider, | 314 this.resourceProvider, |
| 309 PubPackageMapProvider packageMapProvider, | 315 PubPackageMapProvider packageMapProvider, |
| 310 Index _index, | 316 Index _index, |
| 311 this.serverPlugin, | 317 this.serverPlugin, |
| 312 this.options, | 318 this.options, |
| 313 this.defaultSdkCreator, | 319 this.defaultSdkCreator, |
| 314 this.instrumentationService, | 320 this.instrumentationService, |
| 315 {ResolverProvider packageResolverProvider: null, | 321 {ResolverProvider fileResolverProvider: null, |
| 322 ResolverProvider packageResolverProvider: null, |
| 316 bool useSingleContextManager: false, | 323 bool useSingleContextManager: false, |
| 317 this.rethrowExceptions: true}) | 324 this.rethrowExceptions: true}) |
| 318 : index = _index, | 325 : index = _index, |
| 319 searchEngine = _index != null ? new SearchEngineImpl(_index) : null { | 326 searchEngine = _index != null ? new SearchEngineImpl(_index) : null { |
| 320 _performance = performanceDuringStartup; | 327 _performance = performanceDuringStartup; |
| 321 defaultContextOptions.incremental = true; | 328 defaultContextOptions.incremental = true; |
| 322 defaultContextOptions.incrementalApi = | 329 defaultContextOptions.incrementalApi = |
| 323 options.enableIncrementalResolutionApi; | 330 options.enableIncrementalResolutionApi; |
| 324 defaultContextOptions.incrementalValidation = | 331 defaultContextOptions.incrementalValidation = |
| 325 options.enableIncrementalResolutionValidation; | 332 options.enableIncrementalResolutionValidation; |
| 326 defaultContextOptions.generateImplicitErrors = false; | 333 defaultContextOptions.generateImplicitErrors = false; |
| 327 operationQueue = new ServerOperationQueue(); | 334 operationQueue = new ServerOperationQueue(); |
| 328 sdkManager = new DartSdkManager(defaultSdkCreator); | 335 sdkManager = new DartSdkManager(defaultSdkCreator); |
| 329 if (useSingleContextManager) { | 336 if (useSingleContextManager) { |
| 330 contextManager = new SingleContextManager(resourceProvider, sdkManager, | 337 contextManager = new SingleContextManager(resourceProvider, sdkManager, |
| 331 packageResolverProvider, analyzedFilesGlobs, defaultContextOptions); | 338 packageResolverProvider, analyzedFilesGlobs, defaultContextOptions); |
| 332 } else { | 339 } else { |
| 333 contextManager = new ContextManagerImpl( | 340 contextManager = new ContextManagerImpl( |
| 334 resourceProvider, | 341 resourceProvider, |
| 335 sdkManager, | 342 sdkManager, |
| 336 packageResolverProvider, | 343 packageResolverProvider, |
| 337 packageMapProvider, | 344 packageMapProvider, |
| 338 analyzedFilesGlobs, | 345 analyzedFilesGlobs, |
| 339 instrumentationService, | 346 instrumentationService, |
| 340 defaultContextOptions); | 347 defaultContextOptions); |
| 341 } | 348 } |
| 349 this.fileResolverProvider = fileResolverProvider; |
| 342 ServerContextManagerCallbacks contextManagerCallbacks = | 350 ServerContextManagerCallbacks contextManagerCallbacks = |
| 343 new ServerContextManagerCallbacks(this, resourceProvider); | 351 new ServerContextManagerCallbacks(this, resourceProvider); |
| 344 contextManager.callbacks = contextManagerCallbacks; | 352 contextManager.callbacks = contextManagerCallbacks; |
| 345 _noErrorNotification = options.noErrorNotification; | 353 _noErrorNotification = options.noErrorNotification; |
| 346 AnalysisEngine.instance.logger = new AnalysisLogger(this); | 354 AnalysisEngine.instance.logger = new AnalysisLogger(this); |
| 347 _onAnalysisStartedController = new StreamController.broadcast(); | 355 _onAnalysisStartedController = new StreamController.broadcast(); |
| 348 _onFileAnalyzedController = new StreamController.broadcast(); | 356 _onFileAnalyzedController = new StreamController.broadcast(); |
| 349 _onPriorityChangeController = | 357 _onPriorityChangeController = |
| 350 new StreamController<PriorityChangeEvent>.broadcast(); | 358 new StreamController<PriorityChangeEvent>.broadcast(); |
| 351 running = true; | 359 running = true; |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 | 1557 |
| 1550 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); | 1558 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); |
| 1551 | 1559 |
| 1552 @override | 1560 @override |
| 1553 AnalysisContext addContext( | 1561 AnalysisContext addContext( |
| 1554 Folder folder, AnalysisOptions options, FolderDisposition disposition) { | 1562 Folder folder, AnalysisOptions options, FolderDisposition disposition) { |
| 1555 InternalAnalysisContext context = | 1563 InternalAnalysisContext context = |
| 1556 AnalysisEngine.instance.createAnalysisContext(); | 1564 AnalysisEngine.instance.createAnalysisContext(); |
| 1557 context.contentCache = analysisServer.overlayState; | 1565 context.contentCache = analysisServer.overlayState; |
| 1558 analysisServer.folderMap[folder] = context; | 1566 analysisServer.folderMap[folder] = context; |
| 1567 context.fileResolverProvider = analysisServer.fileResolverProvider; |
| 1559 context.sourceFactory = | 1568 context.sourceFactory = |
| 1560 _createSourceFactory(context, options, disposition, folder); | 1569 _createSourceFactory(context, options, disposition, folder); |
| 1561 context.analysisOptions = options; | 1570 context.analysisOptions = options; |
| 1562 analysisServer._onContextsChangedController | 1571 analysisServer._onContextsChangedController |
| 1563 .add(new ContextsChangedEvent(added: [context])); | 1572 .add(new ContextsChangedEvent(added: [context])); |
| 1564 analysisServer.schedulePerformAnalysisOperation(context); | 1573 analysisServer.schedulePerformAnalysisOperation(context); |
| 1574 |
| 1565 return context; | 1575 return context; |
| 1566 } | 1576 } |
| 1567 | 1577 |
| 1568 @override | 1578 @override |
| 1569 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1579 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 1570 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1580 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
| 1571 if (context != null) { | 1581 if (context != null) { |
| 1572 ApplyChangesStatus changesStatus = context.applyChanges(changeSet); | 1582 ApplyChangesStatus changesStatus = context.applyChanges(changeSet); |
| 1573 if (changesStatus.hasChanges) { | 1583 if (changesStatus.hasChanges) { |
| 1574 analysisServer.schedulePerformAnalysisOperation(context); | 1584 analysisServer.schedulePerformAnalysisOperation(context); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 // The embedder file has no mappings, so use the default Dart SDK. | 1640 // The embedder file has no mappings, so use the default Dart SDK. |
| 1631 resolvers.add(new DartUriResolver( | 1641 resolvers.add(new DartUriResolver( |
| 1632 analysisServer.sdkManager.getSdkForOptions(options))); | 1642 analysisServer.sdkManager.getSdkForOptions(options))); |
| 1633 } else { | 1643 } else { |
| 1634 // The embedder uri resolver has mappings, use it instead of the default | 1644 // The embedder uri resolver has mappings, use it instead of the default |
| 1635 // Dart SDK uri resolver. | 1645 // Dart SDK uri resolver. |
| 1636 resolvers.add(new DartUriResolver(sdk)); | 1646 resolvers.add(new DartUriResolver(sdk)); |
| 1637 } | 1647 } |
| 1638 | 1648 |
| 1639 resolvers.addAll(packageUriResolvers); | 1649 resolvers.addAll(packageUriResolvers); |
| 1640 resolvers.add(new ResourceUriResolver(resourceProvider)); | 1650 if (context.fileResolverProvider == null) { |
| 1651 resolvers.add(new ResourceUriResolver(resourceProvider)); |
| 1652 } else { |
| 1653 resolvers.add(context.fileResolverProvider(folder)); |
| 1654 } |
| 1641 return new SourceFactory(resolvers, disposition.packages); | 1655 return new SourceFactory(resolvers, disposition.packages); |
| 1642 } | 1656 } |
| 1643 } | 1657 } |
| 1644 | 1658 |
| 1645 /** | 1659 /** |
| 1646 * A class used by [AnalysisServer] to record performance information | 1660 * A class used by [AnalysisServer] to record performance information |
| 1647 * such as request latency. | 1661 * such as request latency. |
| 1648 */ | 1662 */ |
| 1649 class ServerPerformance { | 1663 class ServerPerformance { |
| 1650 /** | 1664 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 /** | 1750 /** |
| 1737 * The [PerformanceTag] for time spent in server request handlers. | 1751 * The [PerformanceTag] for time spent in server request handlers. |
| 1738 */ | 1752 */ |
| 1739 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1753 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1740 | 1754 |
| 1741 /** | 1755 /** |
| 1742 * The [PerformanceTag] for time spent in split store microtasks. | 1756 * The [PerformanceTag] for time spent in split store microtasks. |
| 1743 */ | 1757 */ |
| 1744 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1758 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1745 } | 1759 } |
| OLD | NEW |