Skip to content

Commit 3c3dd78

Browse files
keertipCommit Queue
authored and
Commit Queue
committed
Reland adding a pass to fix pubspec during dart fix runs
Change-Id: I48d2cd1e4023129e62ef371b452873a320ce0461 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337160 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Keerti Parthasarathy <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent d5f0643 commit 3c3dd78

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pkg/dartdev/lib/src/analysis_server.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ class AnalysisServer {
199199
}
200200

201201
Future<EditBulkFixesResult> requestBulkFixes(
202-
String filePath, bool inTestMode, List<String> codes) {
202+
String filePath, bool inTestMode, List<String> codes,
203+
{bool updatePubspec = false}) {
203204
return _sendCommand('edit.bulkFixes', params: <String, dynamic>{
204205
'included': [path.canonicalize(filePath)],
205206
'inTestMode': inTestMode,
207+
'updatePubspec': updatePubspec,
206208
if (codes.isNotEmpty) 'codes': codes,
207209
}).then((result) {
208210
return EditBulkFixesResult.fromJson(
@@ -212,13 +214,18 @@ class AnalysisServer {
212214

213215
Future<void> shutdown({Duration? timeout}) async {
214216
// Request shutdown.
215-
final Future<void> future = _sendCommand('server.shutdown').then((Map<String, dynamic> value) {
217+
final Future<void> future =
218+
_sendCommand('server.shutdown').then((Map<String, dynamic> value) {
216219
_shutdownResponseReceived = true;
217220
return;
218221
});
219-
await (timeout != null ? future.timeout(timeout, onTimeout: () {
220-
log.stderr('The analysis server timed out while shutting down.');
221-
}) : future).whenComplete(dispose);
222+
await (timeout != null
223+
? future.timeout(timeout, onTimeout: () {
224+
log.stderr(
225+
'The analysis server timed out while shutting down.');
226+
})
227+
: future)
228+
.whenComplete(dispose);
222229
}
223230

224231
/// Send an `analysis.updateContent` request with the given [files].

pkg/dartdev/lib/src/commands/fix.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed
151151
// TODO(brianwilkerson) Be more intelligent about detecting infinite
152152
// loops so that we can increase [maxPasses].
153153
} while (pass < maxPasses && edits.isNotEmpty);
154+
// If there are no more dart edits, check if there are any changes
155+
// to pubspec
156+
if (edits.isEmpty && detailsMap.isNotEmpty) {
157+
var fixes = await server.requestBulkFixes(fixPath, inTestMode, [],
158+
updatePubspec: true);
159+
_mergeDetails(detailsMap, fixes.details);
160+
edits = fixes.edits;
161+
_applyEdits(server, edits);
162+
}
154163
return _FixRequestResult(details: detailsMap);
155164
}
156165

0 commit comments

Comments
 (0)