@@ -21,6 +21,7 @@ import 'package:analysis_server/src/services/completion/postfix/postfix_completi
21
21
import 'package:analysis_server/src/services/completion/statement/statement_completion.dart' ;
22
22
import 'package:analysis_server/src/services/correction/assist.dart' ;
23
23
import 'package:analysis_server/src/services/correction/assist_internal.dart' ;
24
+ import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart' ;
24
25
import 'package:analysis_server/src/services/correction/change_workspace.dart' ;
25
26
import 'package:analysis_server/src/services/correction/fix.dart' ;
26
27
import 'package:analysis_server/src/services/correction/fix/analysis_options/fix_generator.dart' ;
@@ -37,7 +38,6 @@ import 'package:analyzer/dart/analysis/results.dart';
37
38
import 'package:analyzer/dart/analysis/session.dart' ;
38
39
import 'package:analyzer/dart/element/element.dart' ;
39
40
import 'package:analyzer/error/error.dart' as engine;
40
- import 'package:analyzer/error/error.dart' ;
41
41
import 'package:analyzer/exception/exception.dart' ;
42
42
import 'package:analyzer/file_system/file_system.dart' ;
43
43
import 'package:analyzer/source/line_info.dart' ;
@@ -111,34 +111,11 @@ class EditDomainHandler extends AbstractRequestHandler {
111
111
resource.collectDartFilePaths (paths);
112
112
}
113
113
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);
142
119
server.sendResponse (response);
143
120
} catch (exception, stackTrace) {
144
121
server.sendServerErrorNotification ('Exception while getting bulk fixes' ,
@@ -859,39 +836,6 @@ error.errorCode: ${error.errorCode}
859
836
server.sendResponse (result.toResponse (request.id));
860
837
}
861
838
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
-
895
839
YamlMap _getOptions (SourceFactory sourceFactory, String content) {
896
840
var optionsProvider = AnalysisOptionsProvider (sourceFactory);
897
841
try {
0 commit comments