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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 List<AstNode> nodes = <AstNode>[]; | 692 List<AstNode> nodes = <AstNode>[]; |
693 for (CompilationUnit unit in units) { | 693 for (CompilationUnit unit in units) { |
694 AstNode node = new NodeLocator(offset).searchWithin(unit); | 694 AstNode node = new NodeLocator(offset).searchWithin(unit); |
695 if (node != null) { | 695 if (node != null) { |
696 nodes.add(node); | 696 nodes.add(node); |
697 } | 697 } |
698 } | 698 } |
699 return nodes; | 699 return nodes; |
700 } | 700 } |
701 | 701 |
702 // TODO(brianwilkerson) Add the following method after 'prioritySources' has | |
703 // been added to InternalAnalysisContext. | |
704 // /** | |
705 // * Return a list containing the full names of all of the sources that are | |
706 // * priority sources. | |
707 // */ | |
708 // List<String> getPriorityFiles() { | |
709 // List<String> priorityFiles = new List<String>(); | |
710 // folderMap.values.forEach((ContextDirectory directory) { | |
711 // InternalAnalysisContext context = directory.context; | |
712 // context.prioritySources.forEach((Source source) { | |
713 // priorityFiles.add(source.fullName); | |
714 // }); | |
715 // }); | |
716 // return priorityFiles; | |
717 // } | |
718 | |
719 /** | 702 /** |
720 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. | 703 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. |
721 * | 704 * |
722 * May be empty, but not `null`. | 705 * May be empty, but not `null`. |
723 */ | 706 */ |
724 List<CompilationUnit> getResolvedCompilationUnits(String path) { | 707 List<CompilationUnit> getResolvedCompilationUnits(String path) { |
725 List<CompilationUnit> units = <CompilationUnit>[]; | 708 List<CompilationUnit> units = <CompilationUnit>[]; |
726 ContextSourcePair contextSource = getContextSourcePair(path); | 709 ContextSourcePair contextSource = getContextSourcePair(path); |
727 // prepare AnalysisContext | 710 // prepare AnalysisContext |
728 AnalysisContext context = contextSource.context; | 711 AnalysisContext context = contextSource.context; |
729 if (context == null) { | 712 if (context == null) { |
730 return units; | 713 return units; |
731 } | 714 } |
732 // add a unit for each unit/library combination | 715 // add a unit for each unit/library combination |
733 runWithWorkingCacheSize(context, () { | 716 runWithWorkingCacheSize(context, () { |
734 Source unitSource = contextSource.source; | 717 Source unitSource = contextSource.source; |
735 List<Source> librarySources = context.getLibrariesContaining(unitSource); | 718 List<Source> librarySources = context.getLibrariesContaining(unitSource); |
736 for (Source librarySource in librarySources) { | 719 for (Source librarySource in librarySources) { |
737 CompilationUnit unit = | 720 CompilationUnit unit = |
738 context.resolveCompilationUnit2(unitSource, librarySource); | 721 context.resolveCompilationUnit2(unitSource, librarySource); |
739 if (unit != null) { | 722 if (unit != null) { |
740 units.add(unit); | 723 units.add(unit); |
741 } | 724 } |
742 } | 725 } |
743 }); | 726 }); |
744 // done | 727 // done |
745 return units; | 728 return units; |
746 } | 729 } |
747 | 730 |
| 731 // TODO(brianwilkerson) Add the following method after 'prioritySources' has |
| 732 // been added to InternalAnalysisContext. |
| 733 // /** |
| 734 // * Return a list containing the full names of all of the sources that are |
| 735 // * priority sources. |
| 736 // */ |
| 737 // List<String> getPriorityFiles() { |
| 738 // List<String> priorityFiles = new List<String>(); |
| 739 // folderMap.values.forEach((ContextDirectory directory) { |
| 740 // InternalAnalysisContext context = directory.context; |
| 741 // context.prioritySources.forEach((Source source) { |
| 742 // priorityFiles.add(source.fullName); |
| 743 // }); |
| 744 // }); |
| 745 // return priorityFiles; |
| 746 // } |
| 747 |
748 /** | 748 /** |
749 * Handle a [request] that was read from the communication channel. | 749 * Handle a [request] that was read from the communication channel. |
750 */ | 750 */ |
751 void handleRequest(Request request) { | 751 void handleRequest(Request request) { |
752 _performance.logRequest(request); | 752 _performance.logRequest(request); |
753 runZoned(() { | 753 runZoned(() { |
754 ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() { | 754 ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() { |
755 int count = handlers.length; | 755 int count = handlers.length; |
756 for (int i = 0; i < count; i++) { | 756 for (int i = 0; i < count; i++) { |
757 try { | 757 try { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 for (AnalysisContext context in _getContexts(roots)) { | 922 for (AnalysisContext context in _getContexts(roots)) { |
923 operationQueue.contextRemoved(context); | 923 operationQueue.contextRemoved(context); |
924 } | 924 } |
925 } | 925 } |
926 // Instruct the contextDirectoryManager to rebuild all contexts from | 926 // Instruct the contextDirectoryManager to rebuild all contexts from |
927 // scratch. | 927 // scratch. |
928 contextManager.refresh(roots); | 928 contextManager.refresh(roots); |
929 } | 929 } |
930 | 930 |
931 /** | 931 /** |
| 932 * Schedule cache consistency validation in [context]. |
| 933 * The most of the validation must be done asynchronously. |
| 934 */ |
| 935 void scheduleCacheConsistencyValidation(AnalysisContext context) { |
| 936 if (context is InternalAnalysisContext) { |
| 937 CacheConsistencyValidator validator = context.cacheConsistencyValidator; |
| 938 List<Source> sources = validator.getSourcesToComputeModificationTimes(); |
| 939 // Compute modification times and notify the validator asynchronously. |
| 940 new Future(() async { |
| 941 try { |
| 942 List<int> modificationTimes = |
| 943 await resourceProvider.getModificationTimes(sources); |
| 944 bool cacheInconsistencyFixed = validator |
| 945 .sourceModificationTimesComputed(sources, modificationTimes); |
| 946 if (cacheInconsistencyFixed) { |
| 947 scheduleOperation(new PerformAnalysisOperation(context, false)); |
| 948 } |
| 949 } catch (exception, stackTrace) { |
| 950 sendServerErrorNotification( |
| 951 'Failed to check cache consistency', exception, stackTrace); |
| 952 } |
| 953 }); |
| 954 } |
| 955 } |
| 956 |
| 957 /** |
932 * Schedules execution of the given [ServerOperation]. | 958 * Schedules execution of the given [ServerOperation]. |
933 */ | 959 */ |
934 void scheduleOperation(ServerOperation operation) { | 960 void scheduleOperation(ServerOperation operation) { |
935 addOperation(operation); | 961 addOperation(operation); |
936 _schedulePerformOperation(); | 962 _schedulePerformOperation(); |
937 } | 963 } |
938 | 964 |
939 /** | 965 /** |
940 * Schedules analysis of the given context. | 966 * Schedules analysis of the given context. |
941 */ | 967 */ |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 /** | 1790 /** |
1765 * The [PerformanceTag] for time spent in server request handlers. | 1791 * The [PerformanceTag] for time spent in server request handlers. |
1766 */ | 1792 */ |
1767 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1793 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
1768 | 1794 |
1769 /** | 1795 /** |
1770 * The [PerformanceTag] for time spent in split store microtasks. | 1796 * The [PerformanceTag] for time spent in split store microtasks. |
1771 */ | 1797 */ |
1772 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1798 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
1773 } | 1799 } |
OLD | NEW |