| 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'; | 9 import 'dart:core'; |
| 10 import 'dart:io' as io; | 10 import 'dart:io' as io; |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 if (name != null) { | 373 if (name != null) { |
| 374 if (name == 'stdout') { | 374 if (name == 'stdout') { |
| 375 sink = io.stdout; | 375 sink = io.stdout; |
| 376 } else if (name.startsWith('file:')) { | 376 } else if (name.startsWith('file:')) { |
| 377 String path = name.substring('file:'.length); | 377 String path = name.substring('file:'.length); |
| 378 sink = new io.File(path).openWrite(mode: io.FileMode.APPEND); | 378 sink = new io.File(path).openWrite(mode: io.FileMode.APPEND); |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 _analysisPerformanceLogger = new nd.PerformanceLog(sink); | 381 _analysisPerformanceLogger = new nd.PerformanceLog(sink); |
| 382 } | 382 } |
| 383 if (resourceProvider is PhysicalResourceProvider) { | 383 byteStore = _createByteStore(); |
| 384 byteStore = new MemoryCachingByteStore( | |
| 385 new EvictingFileByteStore( | |
| 386 resourceProvider.getStateLocation('.analysis-driver').path, | |
| 387 1024 * 1024 * 1024 /*1 GiB*/), | |
| 388 64 * 1024 * 1024 /*64 MiB*/); | |
| 389 } else { | |
| 390 byteStore = new MemoryByteStore(); | |
| 391 } | |
| 392 analysisDriverScheduler = | 384 analysisDriverScheduler = |
| 393 new nd.AnalysisDriverScheduler(_analysisPerformanceLogger); | 385 new nd.AnalysisDriverScheduler(_analysisPerformanceLogger); |
| 394 analysisDriverScheduler.status.listen(sendStatusNotificationNew); | 386 analysisDriverScheduler.status.listen(sendStatusNotificationNew); |
| 395 analysisDriverScheduler.start(); | 387 analysisDriverScheduler.start(); |
| 396 | 388 |
| 397 if (useSingleContextManager) { | 389 if (useSingleContextManager) { |
| 398 contextManager = new SingleContextManager(resourceProvider, sdkManager, | 390 contextManager = new SingleContextManager(resourceProvider, sdkManager, |
| 399 packageResolverProvider, analyzedFilesGlobs, defaultContextOptions); | 391 packageResolverProvider, analyzedFilesGlobs, defaultContextOptions); |
| 400 } else { | 392 } else { |
| 401 contextManager = new ContextManagerImpl( | 393 contextManager = new ContextManagerImpl( |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 unit = result?.unit; | 822 unit = result?.unit; |
| 831 } else { | 823 } else { |
| 832 unit = await getResolvedCompilationUnit(file); | 824 unit = await getResolvedCompilationUnit(file); |
| 833 } | 825 } |
| 834 if (unit != null) { | 826 if (unit != null) { |
| 835 return new NodeLocator(offset).searchWithin(unit); | 827 return new NodeLocator(offset).searchWithin(unit); |
| 836 } | 828 } |
| 837 return null; | 829 return null; |
| 838 } | 830 } |
| 839 | 831 |
| 840 // TODO(brianwilkerson) Add the following method after 'prioritySources' has | |
| 841 // been added to InternalAnalysisContext. | |
| 842 // /** | |
| 843 // * Return a list containing the full names of all of the sources that are | |
| 844 // * priority sources. | |
| 845 // */ | |
| 846 // List<String> getPriorityFiles() { | |
| 847 // List<String> priorityFiles = new List<String>(); | |
| 848 // folderMap.values.forEach((ContextDirectory directory) { | |
| 849 // InternalAnalysisContext context = directory.context; | |
| 850 // context.prioritySources.forEach((Source source) { | |
| 851 // priorityFiles.add(source.fullName); | |
| 852 // }); | |
| 853 // }); | |
| 854 // return priorityFiles; | |
| 855 // } | |
| 856 | |
| 857 /** | 832 /** |
| 858 * Return a [Future] that completes with the resolved [CompilationUnit] for | 833 * Return a [Future] that completes with the resolved [CompilationUnit] for |
| 859 * the Dart file with the given [path], or with `null` if the file is not a | 834 * the Dart file with the given [path], or with `null` if the file is not a |
| 860 * Dart file or cannot be resolved. | 835 * Dart file or cannot be resolved. |
| 861 */ | 836 */ |
| 862 Future<CompilationUnit> getResolvedCompilationUnit(String path) async { | 837 Future<CompilationUnit> getResolvedCompilationUnit(String path) async { |
| 863 if (options.enableNewAnalysisDriver) { | 838 if (options.enableNewAnalysisDriver) { |
| 864 nd.AnalysisResult result = await getAnalysisResult(path); | 839 nd.AnalysisResult result = await getAnalysisResult(path); |
| 865 return result?.unit; | 840 return result?.unit; |
| 866 } | 841 } |
| 867 ContextSourcePair contextSource = getContextSourcePair(path); | 842 ContextSourcePair contextSource = getContextSourcePair(path); |
| 868 AnalysisContext context = contextSource.context; | 843 AnalysisContext context = contextSource.context; |
| 869 if (context == null) { | 844 if (context == null) { |
| 870 return null; | 845 return null; |
| 871 } | 846 } |
| 872 return runWithActiveContext(context, () { | 847 return runWithActiveContext(context, () { |
| 873 Source unitSource = contextSource.source; | 848 Source unitSource = contextSource.source; |
| 874 List<Source> librarySources = context.getLibrariesContaining(unitSource); | 849 List<Source> librarySources = context.getLibrariesContaining(unitSource); |
| 875 for (Source librarySource in librarySources) { | 850 for (Source librarySource in librarySources) { |
| 876 return context.resolveCompilationUnit2(unitSource, librarySource); | 851 return context.resolveCompilationUnit2(unitSource, librarySource); |
| 877 } | 852 } |
| 878 return null; | 853 return null; |
| 879 }); | 854 }); |
| 880 } | 855 } |
| 881 | 856 |
| 857 // TODO(brianwilkerson) Add the following method after 'prioritySources' has |
| 858 // been added to InternalAnalysisContext. |
| 859 // /** |
| 860 // * Return a list containing the full names of all of the sources that are |
| 861 // * priority sources. |
| 862 // */ |
| 863 // List<String> getPriorityFiles() { |
| 864 // List<String> priorityFiles = new List<String>(); |
| 865 // folderMap.values.forEach((ContextDirectory directory) { |
| 866 // InternalAnalysisContext context = directory.context; |
| 867 // context.prioritySources.forEach((Source source) { |
| 868 // priorityFiles.add(source.fullName); |
| 869 // }); |
| 870 // }); |
| 871 // return priorityFiles; |
| 872 // } |
| 873 |
| 882 /** | 874 /** |
| 883 * Handle a [request] that was read from the communication channel. | 875 * Handle a [request] that was read from the communication channel. |
| 884 */ | 876 */ |
| 885 void handleRequest(Request request) { | 877 void handleRequest(Request request) { |
| 886 _performance.logRequest(request); | 878 _performance.logRequest(request); |
| 887 runZoned(() { | 879 runZoned(() { |
| 888 ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() { | 880 ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() { |
| 889 int count = handlers.length; | 881 int count = handlers.length; |
| 890 for (int i = 0; i < count; i++) { | 882 for (int i = 0; i < count; i++) { |
| 891 try { | 883 try { |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 | 1650 |
| 1659 void _computingPackageMap(bool computing) { | 1651 void _computingPackageMap(bool computing) { |
| 1660 if (serverServices.contains(ServerService.STATUS)) { | 1652 if (serverServices.contains(ServerService.STATUS)) { |
| 1661 PubStatus pubStatus = new PubStatus(computing); | 1653 PubStatus pubStatus = new PubStatus(computing); |
| 1662 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); | 1654 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); |
| 1663 sendNotification(params.toNotification()); | 1655 sendNotification(params.toNotification()); |
| 1664 } | 1656 } |
| 1665 } | 1657 } |
| 1666 | 1658 |
| 1667 /** | 1659 /** |
| 1660 * If the state location can be accessed, return the file byte store, |
| 1661 * otherwise return the memory byte store. |
| 1662 */ |
| 1663 ByteStore _createByteStore() { |
| 1664 const int M = 1024 * 1024 /*1 MiB*/; |
| 1665 const int G = 1024 * 1024 * 1024 /*1 GiB*/; |
| 1666 if (resourceProvider is PhysicalResourceProvider) { |
| 1667 Folder stateLocation = |
| 1668 resourceProvider.getStateLocation('.analysis-driver'); |
| 1669 if (stateLocation != null) { |
| 1670 return new MemoryCachingByteStore( |
| 1671 new EvictingFileByteStore(stateLocation.path, G), 64 * M); |
| 1672 } |
| 1673 } |
| 1674 return new MemoryCachingByteStore(new NullByteStore(), 64 * M); |
| 1675 } |
| 1676 |
| 1677 /** |
| 1668 * Return a set of all contexts whose associated folder is contained within, | 1678 * Return a set of all contexts whose associated folder is contained within, |
| 1669 * or equal to, one of the resources in the given list of [resources]. | 1679 * or equal to, one of the resources in the given list of [resources]. |
| 1670 */ | 1680 */ |
| 1671 Set<AnalysisContext> _getContexts(List<Resource> resources) { | 1681 Set<AnalysisContext> _getContexts(List<Resource> resources) { |
| 1672 Set<AnalysisContext> contexts = new HashSet<AnalysisContext>(); | 1682 Set<AnalysisContext> contexts = new HashSet<AnalysisContext>(); |
| 1673 resources.forEach((Resource resource) { | 1683 resources.forEach((Resource resource) { |
| 1674 if (resource is Folder) { | 1684 if (resource is Folder) { |
| 1675 contexts.addAll(contextManager.contextsInAnalysisRoot(resource)); | 1685 contexts.addAll(contextManager.contextsInAnalysisRoot(resource)); |
| 1676 } | 1686 } |
| 1677 }); | 1687 }); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 /** | 2137 /** |
| 2128 * The [PerformanceTag] for time spent in server request handlers. | 2138 * The [PerformanceTag] for time spent in server request handlers. |
| 2129 */ | 2139 */ |
| 2130 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 2140 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 2131 | 2141 |
| 2132 /** | 2142 /** |
| 2133 * The [PerformanceTag] for time spent in split store microtasks. | 2143 * The [PerformanceTag] for time spent in split store microtasks. |
| 2134 */ | 2144 */ |
| 2135 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2145 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 2136 } | 2146 } |
| OLD | NEW |