Index: pkg/analysis_server/lib/src/analysis_server.dart |
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart |
index 887c34b50d029c11836b7a0beff1b405d9fea9e6..1bfe99a3a52ccd409a98a1d5991a7e8888090a35 100644 |
--- a/pkg/analysis_server/lib/src/analysis_server.dart |
+++ b/pkg/analysis_server/lib/src/analysis_server.dart |
@@ -1270,6 +1270,14 @@ class AnalysisServer { |
// Protocol parsing should have ensured that we never get here. |
throw new AnalysisException('Illegal change type'); |
} |
+ |
+ AnalysisContext containingContext = getContainingContext(file); |
+ |
+ // Check for an implicitly added but missing source. |
+ // (For example, the target of an import might not exist yet.) |
+ // We need to do this before setContents, which changes the stamp. |
+ bool wasMissing = containingContext?.getModificationStamp(source) == -1; |
+ |
overlayState.setContents(source, newContents); |
// If the source does not exist, then it was an overlay-only one. |
// Remove it from contexts. |
@@ -1289,6 +1297,11 @@ class AnalysisServer { |
List<Source> sources = context.getSourcesWithFullName(file); |
sources.forEach((Source source) { |
anyContextUpdated = true; |
+ if (context == containingContext && wasMissing) { |
+ // Promote missing source to an explicitly added Source. |
+ context.applyChanges(new ChangeSet()..addedSource(source)); |
+ schedulePerformAnalysisOperation(context); |
+ } |
if (context.handleContentsChanged( |
source, oldContents, newContents, true)) { |
schedulePerformAnalysisOperation(context); |