Skip to content

Commit 8c1829e

Browse files
committed
bulk fix protocol wiring
Change-Id: If9827b8765eb17c728113aaf23a26df5c8a05738 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155726 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent f169b57 commit 8c1829e

File tree

2 files changed

+12
-77
lines changed

2 files changed

+12
-77
lines changed

pkg/analysis_server/lib/src/edit/edit_domain.dart

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:analysis_server/src/services/completion/postfix/postfix_completi
2121
import 'package:analysis_server/src/services/completion/statement/statement_completion.dart';
2222
import 'package:analysis_server/src/services/correction/assist.dart';
2323
import 'package:analysis_server/src/services/correction/assist_internal.dart';
24+
import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
2425
import 'package:analysis_server/src/services/correction/change_workspace.dart';
2526
import 'package:analysis_server/src/services/correction/fix.dart';
2627
import 'package:analysis_server/src/services/correction/fix/analysis_options/fix_generator.dart';
@@ -37,7 +38,6 @@ import 'package:analyzer/dart/analysis/results.dart';
3738
import 'package:analyzer/dart/analysis/session.dart';
3839
import 'package:analyzer/dart/element/element.dart';
3940
import 'package:analyzer/error/error.dart' as engine;
40-
import 'package:analyzer/error/error.dart';
4141
import 'package:analyzer/exception/exception.dart';
4242
import 'package:analyzer/file_system/file_system.dart';
4343
import 'package:analyzer/source/line_info.dart';
@@ -111,34 +111,11 @@ class EditDomainHandler extends AbstractRequestHandler {
111111
resource.collectDartFilePaths(paths);
112112
}
113113

114-
var errors = await _getErrors(params.included);
115-
116-
var sourceChange = SourceChange('bulk_fix');
117-
118-
// todo (pq): push loop into a BulkFixProcessor
119-
for (var error in errors) {
120-
// todo (pq): filtering will happen in processor
121-
List<AnalysisErrorFixes> fixes;
122-
while (fixes == null) {
123-
try {
124-
fixes = await _computeServerErrorFixes(
125-
request, error.source.fullName, error.offset);
126-
} on InconsistentAnalysisException {
127-
// Loop around to try again to compute the fixes.
128-
}
129-
}
130-
131-
// In the long run we'll want to support the case where the desired fix
132-
// is the first one. For now, we just assume that the first way is the
133-
// only or best way.
134-
var edits = fixes[0].fixes[0].edits;
135-
for (var edit in edits) {
136-
sourceChange.addFileEdit(edit);
137-
}
138-
}
139-
140-
var response =
141-
EditBulkFixesResult(sourceChange.edits).toResponse(request.id);
114+
var workspace = DartChangeWorkspace(server.currentSessions);
115+
var processor = BulkFixProcessor(workspace);
116+
var changeBuilder = await processor.fixErrorsInLibraries(paths);
117+
var response = EditBulkFixesResult(changeBuilder.sourceChange.edits)
118+
.toResponse(request.id);
142119
server.sendResponse(response);
143120
} catch (exception, stackTrace) {
144121
server.sendServerErrorNotification('Exception while getting bulk fixes',
@@ -859,39 +836,6 @@ error.errorCode: ${error.errorCode}
859836
server.sendResponse(result.toResponse(request.id));
860837
}
861838

862-
/// todo (pq): (temporary) -> to be moved and redesigned in BulkFixesProcessor
863-
Future<List<AnalysisError>> _getErrors(List<String> pathsToProcess) async {
864-
var errors = <AnalysisError>[];
865-
866-
var pathsProcessed = <String>{};
867-
for (var path in pathsToProcess) {
868-
var driver = server.getAnalysisDriver(path);
869-
switch (await driver.getSourceKind(path)) {
870-
case SourceKind.PART:
871-
// todo (pq): ensure parts are processed (see `edit_dartfix.dart`)
872-
continue;
873-
break;
874-
case SourceKind.LIBRARY:
875-
var result = await driver.getResolvedLibrary(path);
876-
if (result != null) {
877-
for (var unit in result.units) {
878-
if (pathsToProcess.contains(unit.path) &&
879-
!pathsProcessed.contains(unit.path)) {
880-
for (var error in unit.errors) {
881-
errors.add(error);
882-
}
883-
pathsProcessed.add(unit.path);
884-
}
885-
}
886-
}
887-
break;
888-
default:
889-
break;
890-
}
891-
}
892-
return errors;
893-
}
894-
895839
YamlMap _getOptions(SourceFactory sourceFactory, String content) {
896840
var optionsProvider = AnalysisOptionsProvider(sourceFactory);
897841
try {

pkg/analysis_server/test/edit/bulk_fixes_test.dart

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,21 @@ class BulkFixesTest extends AbstractAnalysisTest {
3636
handler = EditDomainHandler(server);
3737
}
3838

39-
Future<void> test_missingOverride() async {
39+
Future<void> test_unnecessaryNew() async {
4040
createProject();
4141
addAnalysisOptionsFile('''
4242
linter:
4343
rules:
44-
- annotate_overrides
44+
- unnecessary_new
4545
''');
4646
addTestFile('''
47-
class A {
48-
void f() {}
49-
}
50-
class B extends A {
51-
void f() { }
52-
}
47+
class A {}
48+
A f() => new A();
5349
''');
5450

5551
await assertEditEquals('''
56-
class A {
57-
void f() {}
58-
}
59-
class B extends A {
60-
@override
61-
void f() { }
62-
}
52+
class A {}
53+
A f() => A();
6354
''');
6455
}
6556

0 commit comments

Comments
 (0)