| 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:io' as io; | 10 import 'dart:io' as io; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 25 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 26 import 'package:analysis_server/src/single_context_manager.dart'; | 26 import 'package:analysis_server/src/single_context_manager.dart'; |
| 27 import 'package:analyzer/dart/ast/ast.dart'; | 27 import 'package:analyzer/dart/ast/ast.dart'; |
| 28 import 'package:analyzer/dart/element/element.dart'; | 28 import 'package:analyzer/dart/element/element.dart'; |
| 29 import 'package:analyzer/file_system/file_system.dart'; | 29 import 'package:analyzer/file_system/file_system.dart'; |
| 30 import 'package:analyzer/instrumentation/instrumentation.dart'; | 30 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 31 import 'package:analyzer/plugin/resolver_provider.dart'; | 31 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 32 import 'package:analyzer/source/pub_package_map_provider.dart'; | 32 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 33 import 'package:analyzer/src/context/builder.dart'; | 33 import 'package:analyzer/src/context/builder.dart'; |
| 34 import 'package:analyzer/src/dart/ast/utilities.dart'; | 34 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 35 import 'package:analyzer/src/dart/sdk/sdk.dart'; | |
| 36 import 'package:analyzer/src/generated/engine.dart'; | 35 import 'package:analyzer/src/generated/engine.dart'; |
| 37 import 'package:analyzer/src/generated/java_engine.dart'; | 36 import 'package:analyzer/src/generated/java_engine.dart'; |
| 38 import 'package:analyzer/src/generated/java_io.dart'; | 37 import 'package:analyzer/src/generated/java_io.dart'; |
| 39 import 'package:analyzer/src/generated/sdk.dart'; | 38 import 'package:analyzer/src/generated/sdk.dart'; |
| 40 import 'package:analyzer/src/generated/source.dart'; | 39 import 'package:analyzer/src/generated/source.dart'; |
| 41 import 'package:analyzer/src/generated/source_io.dart'; | 40 import 'package:analyzer/src/generated/source_io.dart'; |
| 42 import 'package:analyzer/src/generated/utilities_general.dart'; | 41 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 43 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 42 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 44 import 'package:analyzer/src/summary/pub_summary.dart'; | 43 import 'package:analyzer/src/summary/pub_summary.dart'; |
| 45 import 'package:analyzer/src/task/dart.dart'; | 44 import 'package:analyzer/src/task/dart.dart'; |
| 46 import 'package:analyzer/src/util/glob.dart'; | 45 import 'package:analyzer/src/util/glob.dart'; |
| 47 import 'package:analyzer/task/dart.dart'; | 46 import 'package:analyzer/task/dart.dart'; |
| 48 import 'package:plugin/plugin.dart'; | 47 import 'package:plugin/plugin.dart'; |
| 49 import 'package:yaml/yaml.dart'; | |
| 50 | 48 |
| 51 typedef void OptionUpdater(AnalysisOptionsImpl options); | 49 typedef void OptionUpdater(AnalysisOptionsImpl options); |
| 52 | 50 |
| 53 /** | 51 /** |
| 54 * Enum representing reasons why analysis might be done for a given file. | 52 * Enum representing reasons why analysis might be done for a given file. |
| 55 */ | 53 */ |
| 56 class AnalysisDoneReason { | 54 class AnalysisDoneReason { |
| 57 /** | 55 /** |
| 58 * Analysis of the file completed successfully. | 56 * Analysis of the file completed successfully. |
| 59 */ | 57 */ |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 /** | 1587 /** |
| 1590 * The [ResourceProvider] by which paths are converted into [Resource]s. | 1588 * The [ResourceProvider] by which paths are converted into [Resource]s. |
| 1591 */ | 1589 */ |
| 1592 final ResourceProvider resourceProvider; | 1590 final ResourceProvider resourceProvider; |
| 1593 | 1591 |
| 1594 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); | 1592 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); |
| 1595 | 1593 |
| 1596 @override | 1594 @override |
| 1597 AnalysisContext addContext( | 1595 AnalysisContext addContext( |
| 1598 Folder folder, AnalysisOptions options, FolderDisposition disposition) { | 1596 Folder folder, AnalysisOptions options, FolderDisposition disposition) { |
| 1599 InternalAnalysisContext context = | 1597 ContextBuilder builder = createContextBuilder(folder, options); |
| 1600 AnalysisEngine.instance.createAnalysisContext(); | 1598 AnalysisContext context = builder.buildContext(folder.path); |
| 1601 context.contentCache = analysisServer.overlayState; | 1599 |
| 1602 analysisServer.folderMap[folder] = context; | 1600 // TODO(brianwilkerson) Move bundle discovery into ContextBuilder |
| 1603 context.fileResolverProvider = analysisServer.fileResolverProvider; | |
| 1604 context.sourceFactory = | |
| 1605 _createSourceFactory(context, options, disposition, folder); | |
| 1606 context.analysisOptions = options; | |
| 1607 if (analysisServer.options.enablePubSummaryManager) { | 1601 if (analysisServer.options.enablePubSummaryManager) { |
| 1608 List<LinkedPubPackage> linkedBundles = | 1602 List<LinkedPubPackage> linkedBundles = |
| 1609 analysisServer.pubSummaryManager.getLinkedBundles(context); | 1603 analysisServer.pubSummaryManager.getLinkedBundles(context); |
| 1610 if (linkedBundles.isNotEmpty) { | 1604 if (linkedBundles.isNotEmpty) { |
| 1611 SummaryDataStore store = new SummaryDataStore([]); | 1605 SummaryDataStore store = new SummaryDataStore([]); |
| 1612 for (LinkedPubPackage package in linkedBundles) { | 1606 for (LinkedPubPackage package in linkedBundles) { |
| 1613 store.addBundle(null, package.unlinked); | 1607 store.addBundle(null, package.unlinked); |
| 1614 store.addBundle(null, package.linked); | 1608 store.addBundle(null, package.linked); |
| 1615 } | 1609 } |
| 1616 context.resultProvider = | 1610 (context as InternalAnalysisContext).resultProvider = |
| 1617 new InputPackagesResultProvider(context, store); | 1611 new InputPackagesResultProvider(context, store); |
| 1618 } | 1612 } |
| 1619 } | 1613 } |
| 1620 | 1614 |
| 1615 analysisServer.folderMap[folder] = context; |
| 1621 analysisServer._onContextsChangedController | 1616 analysisServer._onContextsChangedController |
| 1622 .add(new ContextsChangedEvent(added: [context])); | 1617 .add(new ContextsChangedEvent(added: [context])); |
| 1623 analysisServer.schedulePerformAnalysisOperation(context); | 1618 analysisServer.schedulePerformAnalysisOperation(context); |
| 1624 | 1619 |
| 1625 return context; | 1620 return context; |
| 1626 } | 1621 } |
| 1627 | 1622 |
| 1628 @override | 1623 @override |
| 1629 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1624 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 1630 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1625 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
| 1631 if (context != null) { | 1626 if (context != null) { |
| 1632 ApplyChangesStatus changesStatus = context.applyChanges(changeSet); | 1627 ApplyChangesStatus changesStatus = context.applyChanges(changeSet); |
| 1633 if (changesStatus.hasChanges) { | 1628 if (changesStatus.hasChanges) { |
| 1634 analysisServer.schedulePerformAnalysisOperation(context); | 1629 analysisServer.schedulePerformAnalysisOperation(context); |
| 1635 } | 1630 } |
| 1636 List<String> flushedFiles = new List<String>(); | 1631 List<String> flushedFiles = new List<String>(); |
| 1637 for (Source source in changeSet.removedSources) { | 1632 for (Source source in changeSet.removedSources) { |
| 1638 flushedFiles.add(source.fullName); | 1633 flushedFiles.add(source.fullName); |
| 1639 } | 1634 } |
| 1640 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); | 1635 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); |
| 1641 } | 1636 } |
| 1642 } | 1637 } |
| 1643 | 1638 |
| 1644 @override | 1639 @override |
| 1645 void computingPackageMap(bool computing) => | 1640 void computingPackageMap(bool computing) => |
| 1646 analysisServer._computingPackageMap(computing); | 1641 analysisServer._computingPackageMap(computing); |
| 1647 | 1642 |
| 1648 @override | 1643 @override |
| 1644 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) { |
| 1645 String defaultPackageFilePath = null; |
| 1646 String defaultPackagesDirectoryPath = null; |
| 1647 String path = (analysisServer.contextManager as ContextManagerImpl) |
| 1648 .normalizedPackageRoots[folder.path]; |
| 1649 if (path != null) { |
| 1650 Resource resource = resourceProvider.getResource(path); |
| 1651 if (resource.exists) { |
| 1652 if (resource is File) { |
| 1653 defaultPackageFilePath = path; |
| 1654 } else { |
| 1655 defaultPackagesDirectoryPath = path; |
| 1656 } |
| 1657 } |
| 1658 } |
| 1659 |
| 1660 ContextBuilder builder = new ContextBuilder(resourceProvider, |
| 1661 analysisServer.sdkManager, analysisServer.overlayState); |
| 1662 builder.defaultOptions = options; |
| 1663 builder.fileResolverProvider = analysisServer.fileResolverProvider; |
| 1664 builder.defaultPackageFilePath = defaultPackageFilePath; |
| 1665 builder.defaultPackagesDirectoryPath = defaultPackagesDirectoryPath; |
| 1666 return builder; |
| 1667 } |
| 1668 |
| 1669 @override |
| 1649 void moveContext(Folder from, Folder to) { | 1670 void moveContext(Folder from, Folder to) { |
| 1650 // There is nothing to do. | 1671 // There is nothing to do. |
| 1651 // This method is mostly for tests. | 1672 // This method is mostly for tests. |
| 1652 // Context managers manage folders and contexts themselves. | 1673 // Context managers manage folders and contexts themselves. |
| 1653 } | 1674 } |
| 1654 | 1675 |
| 1655 @override | 1676 @override |
| 1656 void removeContext(Folder folder, List<String> flushedFiles) { | 1677 void removeContext(Folder folder, List<String> flushedFiles) { |
| 1657 AnalysisContext context = analysisServer.folderMap.remove(folder); | 1678 AnalysisContext context = analysisServer.folderMap.remove(folder); |
| 1658 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); | 1679 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); |
| 1659 | 1680 |
| 1660 analysisServer.operationQueue.contextRemoved(context); | 1681 analysisServer.operationQueue.contextRemoved(context); |
| 1661 analysisServer._onContextsChangedController | 1682 analysisServer._onContextsChangedController |
| 1662 .add(new ContextsChangedEvent(removed: [context])); | 1683 .add(new ContextsChangedEvent(removed: [context])); |
| 1663 analysisServer.sendContextAnalysisDoneNotifications( | 1684 analysisServer.sendContextAnalysisDoneNotifications( |
| 1664 context, AnalysisDoneReason.CONTEXT_REMOVED); | 1685 context, AnalysisDoneReason.CONTEXT_REMOVED); |
| 1665 context.dispose(); | 1686 context.dispose(); |
| 1666 } | 1687 } |
| 1667 | 1688 |
| 1668 @override | 1689 @override |
| 1669 void updateContextPackageUriResolver(AnalysisContext context) { | 1690 void updateContextPackageUriResolver(AnalysisContext context) { |
| 1670 analysisServer._onContextsChangedController | 1691 analysisServer._onContextsChangedController |
| 1671 .add(new ContextsChangedEvent(changed: [context])); | 1692 .add(new ContextsChangedEvent(changed: [context])); |
| 1672 analysisServer.schedulePerformAnalysisOperation(context); | 1693 analysisServer.schedulePerformAnalysisOperation(context); |
| 1673 } | 1694 } |
| 1674 | |
| 1675 /** | |
| 1676 * Set up a [SourceFactory] that resolves packages as appropriate for the | |
| 1677 * given [disposition]. | |
| 1678 */ | |
| 1679 SourceFactory _createSourceFactory(InternalAnalysisContext context, | |
| 1680 AnalysisOptions options, FolderDisposition disposition, Folder folder) { | |
| 1681 List<UriResolver> resolvers = []; | |
| 1682 List<UriResolver> packageUriResolvers = | |
| 1683 disposition.createPackageUriResolvers(resourceProvider); | |
| 1684 | |
| 1685 // If no embedded URI resolver was provided, defer to a locator-backed one. | |
| 1686 SdkExtensionFinder extFinder = | |
| 1687 disposition.getSdkExtensionFinder(resourceProvider); | |
| 1688 List<String> extFilePaths = extFinder.extensionFilePaths; | |
| 1689 EmbedderYamlLocator locator = | |
| 1690 disposition.getEmbedderLocator(resourceProvider); | |
| 1691 Map<Folder, YamlMap> embedderYamls = locator.embedderYamls; | |
| 1692 EmbedderSdk embedderSdk = new EmbedderSdk(resourceProvider, embedderYamls); | |
| 1693 if (embedderSdk.libraryMap.size() == 0) { | |
| 1694 // There was no embedder file, or the file was empty, so used the default | |
| 1695 // SDK. | |
| 1696 resolvers.add(new DartUriResolver( | |
| 1697 analysisServer.sdkManager.getSdkForOptions(options))); | |
| 1698 } else { | |
| 1699 // The embedder file defines an alternate SDK, so use it. | |
| 1700 List<String> paths = <String>[]; | |
| 1701 for (Folder folder in embedderYamls.keys) { | |
| 1702 paths.add(folder | |
| 1703 .getChildAssumingFile(EmbedderYamlLocator.EMBEDDER_FILE_NAME) | |
| 1704 .path); | |
| 1705 } | |
| 1706 paths.addAll(extFilePaths); | |
| 1707 DartSdk dartSdk = analysisServer.sdkManager | |
| 1708 .getSdk(new SdkDescription(paths, options), () { | |
| 1709 if (extFilePaths.isNotEmpty) { | |
| 1710 embedderSdk.addExtensions(extFinder.urlMappings); | |
| 1711 } | |
| 1712 embedderSdk.analysisOptions = options; | |
| 1713 // TODO(brianwilkerson) Enable summary use after we have decided where | |
| 1714 // summary files for embedder files will live. | |
| 1715 embedderSdk.useSummary = false; | |
| 1716 return embedderSdk; | |
| 1717 }); | |
| 1718 resolvers.add(new DartUriResolver(dartSdk)); | |
| 1719 } | |
| 1720 | |
| 1721 resolvers.addAll(packageUriResolvers); | |
| 1722 UriResolver fileResolver; | |
| 1723 if (context.fileResolverProvider != null) { | |
| 1724 fileResolver = context.fileResolverProvider(folder); | |
| 1725 } | |
| 1726 resolvers.add(fileResolver ?? new ResourceUriResolver(resourceProvider)); | |
| 1727 return new SourceFactory(resolvers, disposition.packages); | |
| 1728 } | |
| 1729 } | 1695 } |
| 1730 | 1696 |
| 1731 /** | 1697 /** |
| 1732 * A class used by [AnalysisServer] to record performance information | 1698 * A class used by [AnalysisServer] to record performance information |
| 1733 * such as request latency. | 1699 * such as request latency. |
| 1734 */ | 1700 */ |
| 1735 class ServerPerformance { | 1701 class ServerPerformance { |
| 1736 /** | 1702 /** |
| 1737 * The creation time and the time when performance information | 1703 * The creation time and the time when performance information |
| 1738 * started to be recorded here. | 1704 * started to be recorded here. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 /** | 1788 /** |
| 1823 * The [PerformanceTag] for time spent in server request handlers. | 1789 * The [PerformanceTag] for time spent in server request handlers. |
| 1824 */ | 1790 */ |
| 1825 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1791 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1826 | 1792 |
| 1827 /** | 1793 /** |
| 1828 * The [PerformanceTag] for time spent in split store microtasks. | 1794 * The [PerformanceTag] for time spent in split store microtasks. |
| 1829 */ | 1795 */ |
| 1830 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1796 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1831 } | 1797 } |
| OLD | NEW |