Skip to content

Commit eb03a16

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
DAS: Use Diagnostic in place of deprecated AnalysisError
Work towards #60635 Change-Id: I0107a65580bc41d769c2a384319225b256df2fbe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426420 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent f59751f commit eb03a16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+224
-209
lines changed

pkg/analysis_server/lib/src/cider/fixes.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:analysis_server_plugin/edit/fix/fix.dart';
77
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
88
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
99
import 'package:analyzer/dart/element/element.dart';
10-
import 'package:analyzer/error/error.dart';
10+
import 'package:analyzer/diagnostic/diagnostic.dart';
1111
import 'package:analyzer/instrumentation/service.dart';
1212
import 'package:analyzer/source/line_info.dart';
1313
import 'package:analyzer/src/dart/analysis/file_state.dart';
@@ -16,15 +16,15 @@ import 'package:analyzer/src/dart/micro/resolve_file.dart';
1616
import 'package:analyzer/src/services/top_level_declarations.dart';
1717

1818
class CiderErrorFixes {
19-
final AnalysisError error;
19+
final Diagnostic diagnostic;
2020

21-
/// The fixes for the [error], might be empty.
21+
/// The fixes for the [diagnostic], might be empty.
2222
final List<Fix> fixes;
2323

2424
final LineInfo lineInfo;
2525

2626
CiderErrorFixes({
27-
required this.error,
27+
required this.diagnostic,
2828
required this.fixes,
2929
required this.lineInfo,
3030
});
@@ -61,7 +61,11 @@ class CiderFixesComputer {
6161
fixes.sort(Fix.compareFixes);
6262

6363
result.add(
64-
CiderErrorFixes(error: error, fixes: fixes, lineInfo: lineInfo),
64+
CiderErrorFixes(
65+
diagnostic: error,
66+
fixes: fixes,
67+
lineInfo: lineInfo,
68+
),
6569
);
6670
}
6771
}

pkg/analysis_server/lib/src/g3/fixes.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analysis_server_plugin/src/correction/fix_in_file_processor.dart
1010
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
1111
import 'package:analysis_server_plugin/src/correction/ignore_diagnostic.dart';
1212
import 'package:analyzer/dart/analysis/results.dart';
13+
import 'package:analyzer/diagnostic/diagnostic.dart';
1314
import 'package:analyzer/error/error.dart';
1415
import 'package:analyzer/file_system/file_system.dart';
1516
import 'package:analyzer/file_system/overlay_file_system.dart';
@@ -71,7 +72,7 @@ class LintFixTester {
7172

7273
var unitResult = resolvedLibrary.unitWithPath(path)!;
7374

74-
AnalysisError error;
75+
Diagnostic diagnostic;
7576
var errors = unitResult.errors;
7677
if (inFile) {
7778
var groups = errors.groupListsBy((error) => error.errorCode);
@@ -81,15 +82,15 @@ class LintFixTester {
8182
'\n$errors\n${groups.keys.toList()}',
8283
);
8384
}
84-
error = errors.first;
85+
diagnostic = errors.first;
8586
} else {
8687
if (errors.length != 1) {
8788
throw StateError('Exactly one lint expected: $errors');
8889
}
89-
error = errors.single;
90+
diagnostic = errors.single;
9091
}
9192

92-
if (error.errorCode is! LintCode) {
93+
if (diagnostic.errorCode is! LintCode) {
9394
throw StateError('A lint expected: $errors');
9495
}
9596

@@ -99,7 +100,7 @@ class LintFixTester {
99100
workspace: workspace,
100101
libraryResult: resolvedLibrary,
101102
unitResult: unitResult,
102-
error: error,
103+
error: diagnostic,
103104
);
104105

105106
List<Fix> fixes;

pkg/analysis_server/lib/src/g3/utilities.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:analyzer/dart/analysis/features.dart';
77
import 'package:analyzer/dart/analysis/results.dart';
88
import 'package:analyzer/dart/ast/ast.dart';
99
import 'package:analyzer/dart/element/element.dart';
10-
import 'package:analyzer/error/error.dart';
10+
import 'package:analyzer/diagnostic/diagnostic.dart';
1111
import 'package:analyzer/error/listener.dart';
1212
import 'package:analyzer/source/line_info.dart';
1313
import 'package:analyzer/src/dart/analysis/experiments.dart';
@@ -33,7 +33,7 @@ String format(String content, {Version? languageVersion}) {
3333

3434
/// Returns a [ParseStringResult]. If successful, the result contains the sorted
3535
/// code. On failure, the result contains the unsorted original code, and the
36-
/// cause of the failure, a list of [AnalysisError]'s.
36+
/// cause of the failure, a list of [Diagnostic]s.
3737
ParseStringResult sortDirectives(String contents, {String? fileName}) {
3838
var (unit, errors) = _parse(contents, fullName: fileName);
3939
var parseErrors =
@@ -52,7 +52,7 @@ ParseStringResult sortDirectives(String contents, {String? fileName}) {
5252
return ParseStringResultImpl(sorter.code, unit, parseErrors);
5353
}
5454

55-
(CompilationUnit, List<AnalysisError>) _parse(
55+
(CompilationUnit, List<Diagnostic>) _parse(
5656
String contents, {
5757
String? fullName,
5858
}) {

pkg/analysis_server/lib/src/handler/legacy/legacy_handler.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart';
1010
import 'package:analysis_server/src/legacy_analysis_server.dart';
1111
import 'package:analysis_server/src/protocol/protocol_internal.dart';
1212
import 'package:analyzer/dart/analysis/results.dart';
13-
import 'package:analyzer/error/error.dart';
13+
import 'package:analyzer/diagnostic/diagnostic.dart';
1414
import 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
1515
import 'package:analyzer/src/util/performance/operation_performance.dart';
1616
import 'package:analyzer/src/utilities/cancellation.dart';
@@ -79,10 +79,10 @@ abstract class LegacyHandler {
7979
/// Handle the [request].
8080
Future<void> handle();
8181

82-
/// Return the number of syntactic errors in the list of [errors].
83-
int numberOfSyntacticErrors(List<AnalysisError> errors) {
82+
/// Return the number of syntactic errors in the list of [diagnostics].
83+
int numberOfSyntacticErrors(List<Diagnostic> diagnostics) {
8484
var numScanParseErrors = 0;
85-
for (var error in errors) {
85+
for (var error in diagnostics) {
8686
if (error.errorCode is ScannerErrorCode ||
8787
error.errorCode is ParserErrorCode) {
8888
numScanParseErrors++;

pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:analysis_server/src/protocol_server.dart' as protocol;
1313
import 'package:analysis_server/src/request_handler_mixin.dart';
1414
import 'package:analyzer/dart/analysis/analysis_options.dart';
1515
import 'package:analyzer/dart/analysis/session.dart';
16-
import 'package:analyzer/error/error.dart';
16+
import 'package:analyzer/diagnostic/diagnostic.dart' as engine;
1717
import 'package:analyzer/file_system/file_system.dart';
1818
import 'package:analyzer/source/line_info.dart';
1919
import 'package:analyzer/src/dart/analysis/results.dart' as engine;
@@ -90,17 +90,17 @@ abstract class AbstractCodeActionsProducer
9090
);
9191
}
9292

93-
/// Create an LSP [Diagnostic] for [error].
93+
/// Create an LSP [Diagnostic] for [diagnostic].
9494
@protected
9595
Diagnostic createDiagnostic(
9696
LineInfo lineInfo,
9797
engine.ErrorsResultImpl result,
98-
AnalysisError error,
98+
engine.Diagnostic diagnostic,
9999
) {
100100
return pluginToDiagnostic(
101101
server.uriConverter,
102102
(_) => lineInfo,
103-
protocol.newAnalysisError_fromEngine(result, error),
103+
protocol.newAnalysisError_fromEngine(result, diagnostic),
104104
supportedTags: supportedDiagnosticTags,
105105
clientSupportsCodeDescription: supportsCodeDescription,
106106
);
@@ -157,7 +157,7 @@ abstract class AbstractCodeActionsProducer
157157
engine.ErrorsResultImpl createResult(
158158
AnalysisSession session,
159159
LineInfo lineInfo,
160-
List<AnalysisError> errors,
160+
List<engine.Diagnostic> diagnostics,
161161
) {
162162
return engine.ErrorsResultImpl(
163163
session: session,
@@ -167,7 +167,7 @@ abstract class AbstractCodeActionsProducer
167167
lineInfo: lineInfo,
168168
isLibrary: true,
169169
isPart: false,
170-
errors: errors,
170+
errors: diagnostics,
171171
analysisOptions: analysisOptions,
172172
);
173173
}

pkg/analysis_server/lib/src/lsp/handlers/commands/simple_edit_handler.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analysis_server/src/lsp/handlers/handlers.dart';
1010
import 'package:analysis_server/src/lsp/mapping.dart';
1111
import 'package:analysis_server/src/lsp/source_edits.dart';
1212
import 'package:analyzer/dart/ast/ast.dart';
13-
import 'package:analyzer/error/error.dart' as engine;
13+
import 'package:analyzer/diagnostic/diagnostic.dart' as engine;
1414
import 'package:analyzer/src/dart/scanner/scanner.dart' as engine;
1515
import 'package:analyzer/src/generated/parser.dart' as engine;
1616
import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -21,8 +21,8 @@ abstract class SimpleEditCommandHandler<S extends AnalysisServer>
2121

2222
String get commandName;
2323

24-
bool hasScanParseErrors(List<engine.AnalysisError> errors) {
25-
return errors.any(
24+
bool hasScanParseErrors(List<engine.Diagnostic> diagnostics) {
25+
return diagnostics.any(
2626
(error) =>
2727
error.errorCode is engine.ScannerErrorCode ||
2828
error.errorCode is engine.ParserErrorCode,

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:analysis_server/src/services/snippets/snippet.dart';
2525
import 'package:analysis_server/src/utilities/extensions/string.dart';
2626
import 'package:analyzer/dart/analysis/results.dart' as server;
2727
import 'package:analyzer/dart/element/element.dart';
28+
import 'package:analyzer/diagnostic/diagnostic.dart' as server;
2829
import 'package:analyzer/error/error.dart' as server;
2930
import 'package:analyzer/source/line_info.dart' as server;
3031
import 'package:analyzer/source/line_info.dart';
@@ -1375,14 +1376,14 @@ lsp.CompletionItem toCompletionItem(
13751376
lsp.Diagnostic toDiagnostic(
13761377
ClientUriConverter uriConverter,
13771378
server.ResolvedUnitResult result,
1378-
server.AnalysisError error, {
1379+
server.Diagnostic diagnostic, {
13791380
required Set<lsp.DiagnosticTag> supportedTags,
13801381
required bool clientSupportsCodeDescription,
13811382
}) {
13821383
return pluginToDiagnostic(
13831384
uriConverter,
13841385
(_) => result.lineInfo,
1385-
server.newAnalysisError_fromEngine(result, error),
1386+
server.newAnalysisError_fromEngine(result, diagnostic),
13861387
supportedTags: supportedTags,
13871388
clientSupportsCodeDescription: clientSupportsCodeDescription,
13881389
);

pkg/analysis_server/lib/src/protocol_server.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,28 @@ String? getReturnTypeString(engine.Element element) {
108108
/// Translates engine errors through the ErrorProcessor.
109109
List<T> mapEngineErrors<T>(
110110
engine.AnalysisResultWithErrors result,
111-
List<engine.AnalysisError> errors,
111+
List<engine.Diagnostic> diagnostics,
112112
T Function(
113113
engine.AnalysisResultWithErrors result,
114-
engine.AnalysisError error, [
114+
engine.Diagnostic diagnostic, [
115115
engine.ErrorSeverity errorSeverity,
116116
])
117117
constructor,
118118
) {
119119
var analysisOptions = result.session.analysisContext
120120
.getAnalysisOptionsForFile(result.file);
121121
var serverErrors = <T>[];
122-
for (var error in errors) {
123-
var processor = ErrorProcessor.getProcessor(analysisOptions, error);
122+
for (var diagnostic in diagnostics) {
123+
var processor = ErrorProcessor.getProcessor(analysisOptions, diagnostic);
124124
if (processor != null) {
125125
var severity = processor.severity;
126126
// Errors with null severity are filtered out.
127127
if (severity != null) {
128128
// Specified severities override.
129-
serverErrors.add(constructor(result, error, severity));
129+
serverErrors.add(constructor(result, diagnostic, severity));
130130
}
131131
} else {
132-
serverErrors.add(constructor(result, error));
132+
serverErrors.add(constructor(result, diagnostic));
133133
}
134134
}
135135
return serverErrors;
@@ -140,7 +140,7 @@ List<T> mapEngineErrors<T>(
140140
/// If an [errorSeverity] is specified, it will override the one in [error].
141141
AnalysisError newAnalysisError_fromEngine(
142142
engine.AnalysisResultWithErrors result,
143-
engine.AnalysisError error, [
143+
engine.Diagnostic error, [
144144
engine.ErrorSeverity? errorSeverity,
145145
]) {
146146
var errorCode = error.errorCode;

pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:analyzer/dart/analysis/results.dart';
1515
import 'package:analyzer/dart/ast/ast.dart';
1616
import 'package:analyzer/dart/ast/token.dart';
1717
import 'package:analyzer/dart/element/element.dart';
18-
import 'package:analyzer/error/error.dart' as engine;
18+
import 'package:analyzer/diagnostic/diagnostic.dart' as engine;
1919
import 'package:analyzer/error/error.dart';
2020
import 'package:analyzer/source/line_info.dart';
2121
import 'package:analyzer/source/source.dart';
@@ -146,7 +146,7 @@ class StatementCompletionProcessor {
146146
// have to test.
147147
StatementCompletion? completion;
148148
SourceChange change = SourceChange('statement-completion');
149-
List<engine.AnalysisError> errors = [];
149+
List<engine.Diagnostic> diagnostics = [];
150150
final Map<String, LinkedEditGroup> linkedPositionGroups =
151151
<String, LinkedEditGroup>{};
152152
Position? exitPosition;
@@ -190,14 +190,14 @@ class StatementCompletionProcessor {
190190
for (var error in statementContext.resolveResult.errors) {
191191
if (error.offset >= node.offset && error.offset <= node.end) {
192192
if (error.errorCode is! HintCode && error.errorCode is! WarningCode) {
193-
errors.add(error);
193+
diagnostics.add(error);
194194
}
195195
}
196196
}
197197

198198
_checkExpressions(node);
199199
if (node is Statement) {
200-
if (errors.isEmpty) {
200+
if (diagnostics.isEmpty) {
201201
if (_complete_ifStatement(node) ||
202202
_complete_forStatement2(node) ||
203203
_complete_whileStatement(node) ||
@@ -219,7 +219,7 @@ class StatementCompletionProcessor {
219219
}
220220
}
221221
} else if (node is Declaration) {
222-
if (errors.isNotEmpty) {
222+
if (diagnostics.isNotEmpty) {
223223
if (_complete_classDeclaration(node) ||
224224
_complete_variableDeclaration(node) ||
225225
_complete_simpleSemicolon(node) ||
@@ -401,7 +401,7 @@ class StatementCompletionProcessor {
401401
if (node is! ClassDeclaration) {
402402
return false;
403403
}
404-
if (node.leftBracket.isSynthetic && errors.length == 1) {
404+
if (node.leftBracket.isSynthetic && diagnostics.length == 1) {
405405
// The space before the left brace is assumed to exist, even if it does not.
406406
var sb = SourceBuilder(file, node.end - 1);
407407
sb.append(' ');
@@ -434,7 +434,7 @@ class StatementCompletionProcessor {
434434
}
435435
var previousInsertions = _lengthOfInsertions();
436436
var delta = 0;
437-
if (errors.isNotEmpty) {
437+
if (diagnostics.isNotEmpty) {
438438
var error = _findError(
439439
ParserErrorCode.EXPECTED_TOKEN,
440440
partialMatch: "';'",
@@ -724,7 +724,7 @@ class StatementCompletionProcessor {
724724
} else if (body is Block) {
725725
if (body.rightBracket.end <= selectionOffset) {
726726
// emptyInitializersAfterBody
727-
errors = []; // Ignore errors; they are for previous statement.
727+
diagnostics = []; // Ignore errors; they are for previous statement.
728728
return false; // If cursor is after closing brace just add newline.
729729
}
730730
}
@@ -965,7 +965,7 @@ class StatementCompletionProcessor {
965965

966966
bool _complete_simpleEnter() {
967967
int offset;
968-
if (errors.isNotEmpty) {
968+
if (diagnostics.isNotEmpty) {
969969
offset = selectionOffset;
970970
} else {
971971
var indent = utils.getLinePrefix(selectionOffset);
@@ -978,7 +978,7 @@ class StatementCompletionProcessor {
978978
}
979979

980980
bool _complete_simpleSemicolon(AstNode node) {
981-
if (errors.length != 1) {
981+
if (diagnostics.length != 1) {
982982
return false;
983983
}
984984
var error = _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'");
@@ -1170,11 +1170,8 @@ class StatementCompletionProcessor {
11701170
);
11711171
}
11721172

1173-
engine.AnalysisError? _findError(
1174-
DiagnosticCode code, {
1175-
Pattern? partialMatch,
1176-
}) {
1177-
return errors.firstWhereOrNull(
1173+
engine.Diagnostic? _findError(DiagnosticCode code, {Pattern? partialMatch}) {
1174+
return diagnostics.firstWhereOrNull(
11781175
(err) =>
11791176
err.errorCode == code &&
11801177
(partialMatch == null ? true : err.message.contains(partialMatch)),
@@ -1279,7 +1276,7 @@ class StatementCompletionProcessor {
12791276
void _removeError(DiagnosticCode diagnosticCode, {Pattern? partialMatch}) {
12801277
var error = _findError(diagnosticCode, partialMatch: partialMatch);
12811278
if (error != null) {
1282-
errors.remove(error);
1279+
diagnostics.remove(error);
12831280
}
12841281
}
12851282

0 commit comments

Comments
 (0)