| 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:math' show max; | 9 import 'dart:math' show max; |
| 10 | 10 |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, | 1031 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 1032 'Invalid overlay change'))); | 1032 'Invalid overlay change'))); |
| 1033 } | 1033 } |
| 1034 } else if (change is RemoveContentOverlay) { | 1034 } else if (change is RemoveContentOverlay) { |
| 1035 newContents = null; | 1035 newContents = null; |
| 1036 } else { | 1036 } else { |
| 1037 // Protocol parsing should have ensured that we never get here. | 1037 // Protocol parsing should have ensured that we never get here. |
| 1038 throw new AnalysisException('Illegal change type'); | 1038 throw new AnalysisException('Illegal change type'); |
| 1039 } | 1039 } |
| 1040 overlayState.setContents(source, newContents); | 1040 overlayState.setContents(source, newContents); |
| 1041 // If the source does not exist, then it was an overlay-only one. |
| 1042 // Remove it from contexts. |
| 1043 if (newContents == null && !source.exists()) { |
| 1044 for (InternalAnalysisContext context in folderMap.values) { |
| 1045 List<Source> sources = context.getSourcesWithFullName(file); |
| 1046 ChangeSet changeSet = new ChangeSet(); |
| 1047 sources.forEach(changeSet.removedSource); |
| 1048 context.applyChanges(changeSet); |
| 1049 schedulePerformAnalysisOperation(context); |
| 1050 } |
| 1051 return; |
| 1052 } |
| 1041 // Update all contexts. | 1053 // Update all contexts. |
| 1054 bool anyContextUpdated = false; |
| 1042 for (InternalAnalysisContext context in folderMap.values) { | 1055 for (InternalAnalysisContext context in folderMap.values) { |
| 1043 List<Source> sources = context.getSourcesWithFullName(file); | 1056 List<Source> sources = context.getSourcesWithFullName(file); |
| 1044 sources.forEach((Source source) { | 1057 sources.forEach((Source source) { |
| 1058 anyContextUpdated = true; |
| 1045 if (context.handleContentsChanged( | 1059 if (context.handleContentsChanged( |
| 1046 source, oldContents, newContents, true)) { | 1060 source, oldContents, newContents, true)) { |
| 1047 schedulePerformAnalysisOperation(context); | 1061 schedulePerformAnalysisOperation(context); |
| 1048 } else { | 1062 } else { |
| 1049 // When the client sends any change for a source, we should resend | 1063 // When the client sends any change for a source, we should resend |
| 1050 // subscribed notifications, even if there were no changes in the | 1064 // subscribed notifications, even if there were no changes in the |
| 1051 // source contents. | 1065 // source contents. |
| 1052 // TODO(scheglov) consider checking if there are subscriptions. | 1066 // TODO(scheglov) consider checking if there are subscriptions. |
| 1053 if (AnalysisEngine.isDartFileName(file)) { | 1067 if (AnalysisEngine.isDartFileName(file)) { |
| 1054 List<CompilationUnit> dartUnits = | 1068 List<CompilationUnit> dartUnits = |
| 1055 context.ensureResolvedDartUnits(source); | 1069 context.ensureResolvedDartUnits(source); |
| 1056 if (dartUnits != null) { | 1070 if (dartUnits != null) { |
| 1057 AnalysisErrorInfo errorInfo = context.getErrors(source); | 1071 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 1058 for (var dartUnit in dartUnits) { | 1072 for (var dartUnit in dartUnits) { |
| 1059 scheduleNotificationOperations(this, file, errorInfo.lineInfo, | 1073 scheduleNotificationOperations(this, file, errorInfo.lineInfo, |
| 1060 context, null, dartUnit, errorInfo.errors); | 1074 context, null, dartUnit, errorInfo.errors); |
| 1061 scheduleIndexOperation(this, file, context, dartUnit); | 1075 scheduleIndexOperation(this, file, context, dartUnit); |
| 1062 } | 1076 } |
| 1063 } else { | 1077 } else { |
| 1064 schedulePerformAnalysisOperation(context); | 1078 schedulePerformAnalysisOperation(context); |
| 1065 } | 1079 } |
| 1066 } | 1080 } |
| 1067 } | 1081 } |
| 1068 }); | 1082 }); |
| 1069 } | 1083 } |
| 1084 // The source is not analyzed by any context, add to the containing one. |
| 1085 if (!anyContextUpdated) { |
| 1086 AnalysisContext context = contextSource.context; |
| 1087 if (context != null && source != null) { |
| 1088 ChangeSet changeSet = new ChangeSet(); |
| 1089 changeSet.addedSource(source); |
| 1090 context.applyChanges(changeSet); |
| 1091 schedulePerformAnalysisOperation(context); |
| 1092 } |
| 1093 } |
| 1070 }); | 1094 }); |
| 1071 } | 1095 } |
| 1072 | 1096 |
| 1073 /** | 1097 /** |
| 1074 * Use the given updaters to update the values of the options in every | 1098 * Use the given updaters to update the values of the options in every |
| 1075 * existing analysis context. | 1099 * existing analysis context. |
| 1076 */ | 1100 */ |
| 1077 void updateOptions(List<OptionUpdater> optionUpdaters) { | 1101 void updateOptions(List<OptionUpdater> optionUpdaters) { |
| 1078 // | 1102 // |
| 1079 // Update existing contexts. | 1103 // Update existing contexts. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 /** | 1447 /** |
| 1424 * The [PerformanceTag] for time spent in server request handlers. | 1448 * The [PerformanceTag] for time spent in server request handlers. |
| 1425 */ | 1449 */ |
| 1426 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1450 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1427 | 1451 |
| 1428 /** | 1452 /** |
| 1429 * The [PerformanceTag] for time spent in split store microtasks. | 1453 * The [PerformanceTag] for time spent in split store microtasks. |
| 1430 */ | 1454 */ |
| 1431 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1455 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1432 } | 1456 } |
| OLD | NEW |