Reland adding a pass to fix pubspec during dart fix runs.

The regressions were fixed with changes to MisssingDependencyValidator in previous CL's.

Change-Id: Id8418811c067535e44fc58c1d2d47afb1c30716f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335864
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
diff --git a/pkg/dartdev/lib/src/analysis_server.dart b/pkg/dartdev/lib/src/analysis_server.dart
index 5aac198..1648f3f 100644
--- a/pkg/dartdev/lib/src/analysis_server.dart
+++ b/pkg/dartdev/lib/src/analysis_server.dart
@@ -199,10 +199,12 @@
   }
 
   Future<EditBulkFixesResult> requestBulkFixes(
-      String filePath, bool inTestMode, List<String> codes) {
+      String filePath, bool inTestMode, List<String> codes,
+      {bool updatePubspec = false}) {
     return _sendCommand('edit.bulkFixes', params: <String, dynamic>{
       'included': [path.canonicalize(filePath)],
       'inTestMode': inTestMode,
+      'updatePubspec': updatePubspec,
       if (codes.isNotEmpty) 'codes': codes,
     }).then((result) {
       return EditBulkFixesResult.fromJson(
@@ -212,13 +214,18 @@
 
   Future<void> shutdown({Duration? timeout}) async {
     // Request shutdown.
-    final Future<void> future = _sendCommand('server.shutdown').then((Map<String, dynamic> value) {
+    final Future<void> future =
+        _sendCommand('server.shutdown').then((Map<String, dynamic> value) {
       _shutdownResponseReceived = true;
       return;
     });
-    await (timeout != null ? future.timeout(timeout, onTimeout: () {
-      log.stderr('The analysis server timed out while shutting down.');
-    }) : future).whenComplete(dispose);
+    await (timeout != null
+            ? future.timeout(timeout, onTimeout: () {
+                log.stderr(
+                    'The analysis server timed out while shutting down.');
+              })
+            : future)
+        .whenComplete(dispose);
   }
 
   /// Send an `analysis.updateContent` request with the given [files].
diff --git a/pkg/dartdev/lib/src/commands/fix.dart b/pkg/dartdev/lib/src/commands/fix.dart
index e262901..097e421 100644
--- a/pkg/dartdev/lib/src/commands/fix.dart
+++ b/pkg/dartdev/lib/src/commands/fix.dart
@@ -151,6 +151,15 @@
         // TODO(brianwilkerson) Be more intelligent about detecting infinite
         //  loops so that we can increase [maxPasses].
       } while (pass < maxPasses && edits.isNotEmpty);
+      // If there are no more dart edits, check if there are any changes
+      // to pubspec
+      if (edits.isEmpty && detailsMap.isNotEmpty) {
+        var fixes = await server.requestBulkFixes(fixPath, inTestMode, [],
+            updatePubspec: true);
+        _mergeDetails(detailsMap, fixes.details);
+        edits = fixes.edits;
+        _applyEdits(server, edits);
+      }
       return _FixRequestResult(details: detailsMap);
     }