@@ -239,19 +239,12 @@ import 'package:analysis_server/src/services/correction/dart/use_not_eq_null.dar
239
239
import 'package:analysis_server/src/services/correction/dart/use_rethrow.dart' ;
240
240
import 'package:analysis_server/src/services/correction/dart/wrap_in_text.dart' ;
241
241
import 'package:analysis_server/src/services/correction/dart/wrap_in_unawaited.dart' ;
242
- import 'package:analysis_server_plugin/edit/dart/correction_producer.dart' ;
243
- import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart' ;
244
- import 'package:analysis_server_plugin/edit/fix/fix.dart' ;
245
242
import 'package:analysis_server_plugin/src/correction/fix_generators.dart' ;
246
243
import 'package:analysis_server_plugin/src/correction/fix_processor.dart' ;
247
244
import 'package:analyzer/error/error.dart' ;
248
245
import 'package:analyzer/src/dart/error/ffi_code.g.dart' ;
249
246
import 'package:analyzer/src/error/codes.dart' ;
250
247
import 'package:analyzer/src/generated/parser.dart' ;
251
- import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart' ;
252
- import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
253
- import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart' ;
254
- import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
255
248
import 'package:linter/src/rules/always_declare_return_types.dart' ;
256
249
import 'package:linter/src/rules/always_put_control_body_on_new_line.dart' ;
257
250
import 'package:linter/src/rules/always_put_required_named_parameters_first.dart' ;
@@ -2001,13 +1994,6 @@ final _builtInParseLintProducers = <LintCode, List<ProducerGenerator>>{
2001
1994
],
2002
1995
};
2003
1996
2004
- Future <List <Fix >> computeFixes (DartFixContext context) async {
2005
- return [
2006
- ...await FixProcessor (context).compute (),
2007
- ...await FixInFileProcessor (context).compute (),
2008
- ];
2009
- }
2010
-
2011
1997
/// Registers each mapping of diagnostic -> list-of-producers with
2012
1998
/// [FixProcessor] .
2013
1999
void registerBuiltInProducers () {
@@ -2026,162 +2012,3 @@ void registerBuiltInProducers() {
2026
2012
IgnoreDiagnosticInAnalysisOptionsFile .new ,
2027
2013
]);
2028
2014
}
2029
-
2030
- /// Computer for Dart "fix all in file" fixes.
2031
- class FixInFileProcessor {
2032
- final DartFixContext context;
2033
-
2034
- FixInFileProcessor (this .context);
2035
-
2036
- Future <List <Fix >> compute () async {
2037
- var error = context.error;
2038
- var errors = context.resolvedResult.errors
2039
- .where ((e) => error.errorCode.name == e.errorCode.name);
2040
- if (errors.length < 2 ) {
2041
- return const < Fix > [];
2042
- }
2043
-
2044
- var instrumentationService = context.instrumentationService;
2045
- var workspace = context.workspace;
2046
- var resolvedResult = context.resolvedResult;
2047
-
2048
- /// Helper to create a [DartFixContextImpl] for a given error.
2049
- DartFixContext createFixContext (AnalysisError error) {
2050
- return DartFixContext (
2051
- instrumentationService: instrumentationService,
2052
- workspace: workspace,
2053
- resolvedResult: resolvedResult,
2054
- error: error,
2055
- );
2056
- }
2057
-
2058
- var generators = _getGenerators (error.errorCode);
2059
-
2060
- var fixes = < Fix > [];
2061
- for (var generator in generators) {
2062
- if (generator (context: StubCorrectionProducerContext .instance)
2063
- .canBeAppliedAcrossSingleFile) {
2064
- _FixState fixState = _EmptyFixState (
2065
- ChangeBuilder (workspace: workspace),
2066
- );
2067
-
2068
- // First try to fix the specific error we started from. We should only
2069
- // include fix-all-in-file when we produce an individual fix at this
2070
- // location.
2071
- fixState = await _fixError (
2072
- createFixContext (error), fixState, generator, error);
2073
-
2074
- // The original error was not fixable, don't continue.
2075
- if (! (fixState.builder as ChangeBuilderImpl ).hasEdits) {
2076
- continue ;
2077
- }
2078
-
2079
- // Compute fixes for the rest of the errors.
2080
- for (var error in errors.where ((item) => item != error)) {
2081
- var fixContext = createFixContext (error);
2082
- fixState = await _fixError (fixContext, fixState, generator, error);
2083
- }
2084
- if (fixState is _NotEmptyFixState ) {
2085
- var sourceChange = fixState.builder.sourceChange;
2086
- if (sourceChange.edits.isNotEmpty && fixState.fixCount > 1 ) {
2087
- var fixKind = fixState.fixKind;
2088
- sourceChange.id = fixKind.id;
2089
- sourceChange.message = fixKind.message;
2090
- fixes.add (Fix (kind: fixKind, change: sourceChange));
2091
- }
2092
- }
2093
- }
2094
- }
2095
- return fixes;
2096
- }
2097
-
2098
- Future <_FixState > _fixError (
2099
- DartFixContext fixContext,
2100
- _FixState fixState,
2101
- ProducerGenerator generator,
2102
- AnalysisError diagnostic,
2103
- ) async {
2104
- var context = CorrectionProducerContext .createResolved (
2105
- applyingBulkFixes: true ,
2106
- dartFixContext: fixContext,
2107
- diagnostic: diagnostic,
2108
- resolvedResult: fixContext.resolvedResult,
2109
- selectionOffset: diagnostic.offset,
2110
- selectionLength: diagnostic.length,
2111
- );
2112
-
2113
- var producer = generator (context: context);
2114
-
2115
- try {
2116
- var localBuilder = fixState.builder.copy ();
2117
- var fixKind = producer.fixKind;
2118
- await producer.compute (localBuilder);
2119
- assert (
2120
- ! producer.canBeAppliedAcrossSingleFile || producer.fixKind == fixKind,
2121
- 'Producers used in bulk fixes must not modify the FixKind during '
2122
- 'computation. $producer changed from $fixKind to ${producer .fixKind }.' ,
2123
- );
2124
-
2125
- var multiFixKind = producer.multiFixKind;
2126
- if (multiFixKind == null ) {
2127
- return fixState;
2128
- }
2129
-
2130
- // TODO(pq): consider discarding the change if the producer's fixKind
2131
- // doesn't match a previously cached one.
2132
- return _NotEmptyFixState (
2133
- builder: localBuilder,
2134
- fixKind: multiFixKind,
2135
- fixCount: fixState.fixCount + 1 ,
2136
- );
2137
- } on ConflictingEditException {
2138
- // If a conflicting edit was added in [compute], then the [localBuilder]
2139
- // is discarded and we revert to the previous state of the builder.
2140
- return fixState;
2141
- }
2142
- }
2143
-
2144
- List <ProducerGenerator > _getGenerators (ErrorCode errorCode) {
2145
- if (errorCode is LintCode ) {
2146
- return registeredFixGenerators.lintProducers[errorCode] ?? [];
2147
- } else {
2148
- // TODO(pq): consider support for multi-generators.
2149
- return registeredFixGenerators.nonLintProducers[errorCode] ?? [];
2150
- }
2151
- }
2152
- }
2153
-
2154
- /// [_FixState] that is still empty.
2155
- class _EmptyFixState implements _FixState {
2156
- @override
2157
- final ChangeBuilder builder;
2158
-
2159
- _EmptyFixState (this .builder);
2160
-
2161
- @override
2162
- int get fixCount => 0 ;
2163
- }
2164
-
2165
- /// State associated with producing fix-all-in-file fixes.
2166
- abstract class _FixState {
2167
- ChangeBuilder get builder;
2168
-
2169
- int get fixCount;
2170
- }
2171
-
2172
- /// [_FixState] that has a fix, so knows its kind.
2173
- class _NotEmptyFixState implements _FixState {
2174
- @override
2175
- final ChangeBuilder builder;
2176
-
2177
- final FixKind fixKind;
2178
-
2179
- @override
2180
- final int fixCount;
2181
-
2182
- _NotEmptyFixState ({
2183
- required this .builder,
2184
- required this .fixKind,
2185
- required this .fixCount,
2186
- });
2187
- }
0 commit comments