@@ -174,6 +174,14 @@ class AnalysisDriver implements AnalysisDriverGeneric {
174174 /// The list of tasks to compute files referencing a name.
175175 final _referencingNameTasks = < _FilesReferencingNameTask > [];
176176
177+ /// The mapping from the files for which errors were requested using
178+ /// [getErrors] to the [Completer] s to report the result.
179+ final _errorsRequestedFiles = < String , List <Completer <ErrorsResult >>> {};
180+
181+ /// The requests from [_errorsRequestedFiles] for files which were found to
182+ /// be parts without known libraries, so delayed.
183+ final _errorsRequestedParts = < String , List <Completer <ErrorsResult >>> {};
184+
177185 /// The mapping from the files for which the index was requested using
178186 /// [getIndex] to the [Completer] s to report the result.
179187 final _indexRequestedFiles =
@@ -385,6 +393,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
385393 _referencingNameTasks.isNotEmpty) {
386394 return AnalysisDriverPriority .interactive;
387395 }
396+ if (_errorsRequestedFiles.isNotEmpty) {
397+ return AnalysisDriverPriority .interactive;
398+ }
388399 if (_indexRequestedFiles.isNotEmpty) {
389400 return AnalysisDriverPriority .interactive;
390401 }
@@ -416,7 +427,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
416427 if (_fileTracker.hasPendingFiles) {
417428 return AnalysisDriverPriority .general;
418429 }
419- if (_requestedParts.isNotEmpty ||
430+ if (_errorsRequestedParts.isNotEmpty ||
431+ _requestedParts.isNotEmpty ||
420432 _partsToAnalyze.isNotEmpty ||
421433 _unitElementSignatureParts.isNotEmpty ||
422434 _unitElementRequestedParts.isNotEmpty) {
@@ -547,19 +559,12 @@ class AnalysisDriver implements AnalysisDriverGeneric {
547559 return null ;
548560 }
549561
550- // Ask the analysis result without unit, so return cached errors.
551- // If no cached analysis result, it will be computed.
552- ResolvedUnitResult analysisResult = _computeAnalysisResult (path);
553-
554- // If not computed yet, because a part file without a known library,
555- // we have to compute the full analysis result, with the unit.
556- analysisResult ?? = await getResult (path);
557- if (analysisResult == null ) {
558- return null ;
559- }
560-
561- return ErrorsResultImpl (currentSession, path, analysisResult.uri,
562- analysisResult.lineInfo, analysisResult.isPart, analysisResult.errors);
562+ var completer = Completer <ErrorsResult >();
563+ _errorsRequestedFiles
564+ .putIfAbsent (path, () => < Completer <ErrorsResult >> [])
565+ .add (completer);
566+ _scheduler.notify (this );
567+ return completer.future;
563568 }
564569
565570 /// Return a [Future] that completes with the list of added files that
@@ -967,6 +972,21 @@ class AnalysisDriver implements AnalysisDriverGeneric {
967972 return ;
968973 }
969974
975+ // Process an error request.
976+ if (_errorsRequestedFiles.isNotEmpty) {
977+ var path = _errorsRequestedFiles.keys.first;
978+ var completers = _errorsRequestedFiles.remove (path);
979+ var result = _computeErrors (path: path, asIsIfPartWithoutLibrary: false );
980+ if (result != null ) {
981+ completers.forEach ((completer) {
982+ completer.complete (result);
983+ });
984+ } else {
985+ _errorsRequestedParts.putIfAbsent (path, () => []).addAll (completers);
986+ }
987+ return ;
988+ }
989+
970990 // Process an index request.
971991 if (_indexRequestedFiles.isNotEmpty) {
972992 String path = _indexRequestedFiles.keys.first;
@@ -1147,6 +1167,17 @@ class AnalysisDriver implements AnalysisDriverGeneric {
11471167 });
11481168 return ;
11491169 }
1170+
1171+ // Compute errors in a part.
1172+ if (_errorsRequestedParts.isNotEmpty) {
1173+ var path = _errorsRequestedParts.keys.first;
1174+ var completers = _errorsRequestedParts.remove (path);
1175+ var result = _computeErrors (path: path, asIsIfPartWithoutLibrary: true );
1176+ completers.forEach ((completer) {
1177+ completer.complete (result);
1178+ });
1179+ return ;
1180+ }
11501181 }
11511182
11521183 /// Remove the file with the given [path] from the list of files to analyze.
@@ -1334,6 +1365,21 @@ class AnalysisDriver implements AnalysisDriverGeneric {
13341365 return Uint8List .fromList (bytes).buffer.asUint32List ();
13351366 }
13361367
1368+ ErrorsResult _computeErrors ({
1369+ @required String path,
1370+ @required bool asIsIfPartWithoutLibrary,
1371+ }) {
1372+ ResolvedUnitResult analysisResult = _computeAnalysisResult (path,
1373+ withUnit: false , asIsIfPartWithoutLibrary: asIsIfPartWithoutLibrary);
1374+
1375+ if (analysisResult == null ) {
1376+ return null ;
1377+ }
1378+
1379+ return ErrorsResultImpl (currentSession, path, analysisResult.uri,
1380+ analysisResult.lineInfo, analysisResult.isPart, analysisResult.errors);
1381+ }
1382+
13371383 AnalysisDriverUnitIndex _computeIndex (String path) {
13381384 AnalysisResult analysisResult = _computeAnalysisResult (path,
13391385 withUnit: false , asIsIfPartWithoutLibrary: true );
0 commit comments