AnalysisDriver. Remove transitionToAnalyzingToIdleIfNoFilesToAnalyze()

It caused race condition via async nature of DAS and AnalysisDriver.

My understanding of the scenario:
1. We started fulling AD with files.
2. We set `priorityFiles`, this notifies the scheduler.
3. We add Dart files to AD.
4. We do something async, this allows the scheduler to ask AD
   to takes the next file, and start analyzing it.
5. We run transitionToAnalyzingToIdleIfNoFilesToAnalyze(), it sees
   there there are no files _to_ analyze (the only file is _being_
   analyzed). So, it turns analysis on/off.
6. DAS sends "analysis: done", `dart analyze` says, I'm done, no errors.
7. AD ends analysis of the file, report errors. Too late.

I believe we don't need this (hackish) method anymore.
1. We switch to analysis status with `priorityFiles`, for good or bad.
2. We are more aggressive now to switch status on/off.

Bug: https://github.com/flutter/flutter/issues/141873
Change-Id: If4e8b74ebdce33b173a686a7b87d14368dfc175d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347421
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/legacy_analysis_server.dart b/pkg/analysis_server/lib/src/legacy_analysis_server.dart
index cb47f83..c80ae84 100644
--- a/pkg/analysis_server/lib/src/legacy_analysis_server.dart
+++ b/pkg/analysis_server/lib/src/legacy_analysis_server.dart
@@ -748,7 +748,6 @@
         throw RequestFailure(Response.unsupportedFeature(
             requestId, e.message ?? 'Unsupported feature.'));
       }
-      analysisDriverScheduler.transitionToAnalyzingToIdleIfNoFilesToAnalyze();
     } finally {
       completer.complete();
     }
diff --git a/pkg/analysis_server/test/analysis_server_test.dart b/pkg/analysis_server/test/analysis_server_test.dart
index 8c19012..86674e7 100644
--- a/pkg/analysis_server/test/analysis_server_test.dart
+++ b/pkg/analysis_server/test/analysis_server_test.dart
@@ -162,12 +162,14 @@
     config.add(name: 'bar', rootPath: barLibFolder.parent.path);
     writePackageConfig(projectPackageConfigFile, config);
 
-    // Allow the server to catch up with everything.
-    await pumpEventQueue(times: 5000);
-    await server.onAnalysisComplete;
-
-    // Expect both errors are gone.
-    expect(await getUriNotExistErrors(), hasLength(0));
+    // Eventually the errors are gone.
+    while (true) {
+      var errors = await getUriNotExistErrors();
+      if (errors.isEmpty) {
+        break;
+      }
+      await pumpEventQueue(times: 5000);
+    }
   }
 
   Future<void> test_serverStatusNotifications_hasFile() async {
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 3deb1fb..3088786 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -2182,7 +2182,9 @@
   Stream<Object> get events => _events;
 
   /// Return `true` if we are currently analyzing code.
-  bool get isAnalyzing => _hasFilesToAnalyze;
+  bool get isAnalyzing {
+    return _statusSupport.currentStatus == AnalysisStatus.ANALYZING;
+  }
 
   bool get isStarted => _started;
 
@@ -2233,17 +2235,6 @@
     _run();
   }
 
-  /// Usually we transition status to analyzing only if there are files to
-  /// analyze. However when used in the server, there are rare cases when
-  /// analysis roots don't have any Dart files, but for consistency we still
-  /// want to get status to transition to analysis, and back to idle.
-  void transitionToAnalyzingToIdleIfNoFilesToAnalyze() {
-    if (!_hasFilesToAnalyze) {
-      _statusSupport.transitionToAnalyzing();
-      _statusSupport.transitionToIdle();
-    }
-  }
-
   /// Return a future that will be completed the next time the status is idle.
   ///
   /// If the status is currently idle, the returned future will be signaled