| 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 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 throw new RequestFailure(new Response(id, | 1263 throw new RequestFailure(new Response(id, |
| 1264 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, | 1264 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 1265 'Invalid overlay change'))); | 1265 'Invalid overlay change'))); |
| 1266 } | 1266 } |
| 1267 } else if (change is RemoveContentOverlay) { | 1267 } else if (change is RemoveContentOverlay) { |
| 1268 newContents = null; | 1268 newContents = null; |
| 1269 } else { | 1269 } else { |
| 1270 // Protocol parsing should have ensured that we never get here. | 1270 // Protocol parsing should have ensured that we never get here. |
| 1271 throw new AnalysisException('Illegal change type'); | 1271 throw new AnalysisException('Illegal change type'); |
| 1272 } | 1272 } |
| 1273 |
| 1274 AnalysisContext containingContext = getContainingContext(file); |
| 1275 |
| 1276 // Check for an implicitly added but missing source. |
| 1277 // (For example, the target of an import might not exist yet.) |
| 1278 // We need to do this before setContents, which changes the stamp. |
| 1279 bool wasMissing = containingContext?.getModificationStamp(source) == -1; |
| 1280 |
| 1273 overlayState.setContents(source, newContents); | 1281 overlayState.setContents(source, newContents); |
| 1274 // If the source does not exist, then it was an overlay-only one. | 1282 // If the source does not exist, then it was an overlay-only one. |
| 1275 // Remove it from contexts. | 1283 // Remove it from contexts. |
| 1276 if (newContents == null && !source.exists()) { | 1284 if (newContents == null && !source.exists()) { |
| 1277 for (InternalAnalysisContext context in analysisContexts) { | 1285 for (InternalAnalysisContext context in analysisContexts) { |
| 1278 List<Source> sources = context.getSourcesWithFullName(file); | 1286 List<Source> sources = context.getSourcesWithFullName(file); |
| 1279 ChangeSet changeSet = new ChangeSet(); | 1287 ChangeSet changeSet = new ChangeSet(); |
| 1280 sources.forEach(changeSet.removedSource); | 1288 sources.forEach(changeSet.removedSource); |
| 1281 context.applyChanges(changeSet); | 1289 context.applyChanges(changeSet); |
| 1282 schedulePerformAnalysisOperation(context); | 1290 schedulePerformAnalysisOperation(context); |
| 1283 } | 1291 } |
| 1284 return; | 1292 return; |
| 1285 } | 1293 } |
| 1286 // Update all contexts. | 1294 // Update all contexts. |
| 1287 bool anyContextUpdated = false; | 1295 bool anyContextUpdated = false; |
| 1288 for (InternalAnalysisContext context in analysisContexts) { | 1296 for (InternalAnalysisContext context in analysisContexts) { |
| 1289 List<Source> sources = context.getSourcesWithFullName(file); | 1297 List<Source> sources = context.getSourcesWithFullName(file); |
| 1290 sources.forEach((Source source) { | 1298 sources.forEach((Source source) { |
| 1291 anyContextUpdated = true; | 1299 anyContextUpdated = true; |
| 1300 if (context == containingContext && wasMissing) { |
| 1301 // Promote missing source to an explicitly added Source. |
| 1302 context.applyChanges(new ChangeSet()..addedSource(source)); |
| 1303 schedulePerformAnalysisOperation(context); |
| 1304 } |
| 1292 if (context.handleContentsChanged( | 1305 if (context.handleContentsChanged( |
| 1293 source, oldContents, newContents, true)) { | 1306 source, oldContents, newContents, true)) { |
| 1294 schedulePerformAnalysisOperation(context); | 1307 schedulePerformAnalysisOperation(context); |
| 1295 } else { | 1308 } else { |
| 1296 // When the client sends any change for a source, we should resend | 1309 // When the client sends any change for a source, we should resend |
| 1297 // subscribed notifications, even if there were no changes in the | 1310 // subscribed notifications, even if there were no changes in the |
| 1298 // source contents. | 1311 // source contents. |
| 1299 // TODO(scheglov) consider checking if there are subscriptions. | 1312 // TODO(scheglov) consider checking if there are subscriptions. |
| 1300 if (AnalysisEngine.isDartFileName(file)) { | 1313 if (AnalysisEngine.isDartFileName(file)) { |
| 1301 List<CompilationUnit> dartUnits = | 1314 List<CompilationUnit> dartUnits = |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 /** | 1716 /** |
| 1704 * The [PerformanceTag] for time spent in server request handlers. | 1717 * The [PerformanceTag] for time spent in server request handlers. |
| 1705 */ | 1718 */ |
| 1706 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1719 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1707 | 1720 |
| 1708 /** | 1721 /** |
| 1709 * The [PerformanceTag] for time spent in split store microtasks. | 1722 * The [PerformanceTag] for time spent in split store microtasks. |
| 1710 */ | 1723 */ |
| 1711 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1724 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1712 } | 1725 } |
| OLD | NEW |