Skip to content

Commit d3b8091

Browse files
author
Dart CI
committed
Version 2.18.0-225.0.dev
Merge commit 'c97f7b7fadca5b6a3e220a20dbefd4eaa3b442ba' into 'dev'
2 parents 6925623 + c97f7b7 commit d3b8091

File tree

167 files changed

+2485
-727
lines changed

Some content is hidden

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

167 files changed

+2485
-727
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ vars = {
109109
"dart_style_rev": "d7b73536a8079331c888b7da539b80e6825270ea", # manually rev'd
110110

111111
"dartdoc_rev": "58348a98b992ce99b95d23131b67227bdb2b4875",
112-
"devtools_rev": "51ac983d2db7eb19b3ce5956cb70b769d74fe784",
112+
"devtools_rev": "0aa619c42a68d6db4c94a7838121811aba8f5eb1",
113113
"ffi_rev": "18b2b549d55009ff594600b04705ff6161681e07",
114114
"file_rev": "0132eeedea2933513bf230513a766a8baeab0c4f",
115115
"fixnum_rev": "164712f6547cdfb2709b752188186baf31fd1730",

pkg/analysis_server/benchmark/perf/flutter_completion_benchmark.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class FlutterCompletionBenchmark extends Benchmark implements FlutterBenchmark {
9595
);
9696

9797
if (!quick) {
98-
// This scenario is relatively easy - the file is small, less then 3KB.
98+
// This scenario is relatively easy - the file is small, less than 3KB.
9999
// But we don't have any prefix to filter, so if we don't restrict the
100100
// number of suggestions, we might spend too much time serializing into
101101
// JSON in the server, and deserializing on the client.

pkg/analysis_server/lib/src/analytics/google_analytics_manager.dart

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class GoogleAnalyticsManager implements AnalyticsManager {
4141
/// was enabled.
4242
final Map<String, int> _lintUsageCounts = {};
4343

44+
/// A map from the name of a diagnostic to a map whose values are the number
45+
/// of times that the severity of the diagnostic was changed to the severity
46+
/// represented by the key.
47+
final Map<String, Map<String, int>> _severityAdjustments = {};
48+
4449
/// Initialize a newly created analytics manager to report to the [analytics]
4550
/// service.
4651
GoogleAnalyticsManager(this.analytics);
@@ -66,12 +71,12 @@ class GoogleAnalyticsManager implements AnalyticsManager {
6671
var name = rule.name;
6772
_lintUsageCounts[name] = (_lintUsageCounts[name] ?? 0) + 1;
6873
}
69-
// TODO(brianwilkerson) Collect other context-dependent information, such
70-
// as which codes have a different severity assigned to them:
71-
// for (var processor in context.analysisOptions.errorProcessors) {
72-
// processor.code;
73-
// processor.severity;
74-
// }
74+
for (var processor in context.analysisOptions.errorProcessors) {
75+
var severity = processor.severity?.name ?? 'ignore';
76+
var severityCounts =
77+
_severityAdjustments.putIfAbsent(processor.code, () => {});
78+
severityCounts[severity] = (severityCounts[severity] ?? 0) + 1;
79+
}
7580
}
7681
}
7782

@@ -140,6 +145,7 @@ class GoogleAnalyticsManager implements AnalyticsManager {
140145
_sendPluginResponseTimes();
141146
_sendNotificationHandlingTimes();
142147
_sendLintUsageCounts();
148+
_sendSeverityAdjustments();
143149

144150
analytics.waitForLastPing(timeout: Duration(milliseconds: 200)).then((_) {
145151
analytics.close();
@@ -227,9 +233,11 @@ class GoogleAnalyticsManager implements AnalyticsManager {
227233
}
228234

229235
void _sendLintUsageCounts() {
230-
analytics.sendEvent('language_server', 'lintUsageCounts', parameters: {
231-
'usageCounts': _lintUsageCounts.toString(),
232-
});
236+
if (_lintUsageCounts.isNotEmpty) {
237+
analytics.sendEvent('language_server', 'lintUsageCounts', parameters: {
238+
'usageCounts': json.encode(_lintUsageCounts),
239+
});
240+
}
233241
}
234242

235243
/// Send information about the notifications handled by the server.
@@ -286,6 +294,15 @@ class GoogleAnalyticsManager implements AnalyticsManager {
286294
'plugins': _pluginData.usageCountData,
287295
});
288296
}
297+
298+
void _sendSeverityAdjustments() {
299+
if (_severityAdjustments.isNotEmpty) {
300+
analytics
301+
.sendEvent('language_server', 'severityAdjustments', parameters: {
302+
'adjustmentCounts': json.encode(_severityAdjustments),
303+
});
304+
}
305+
}
289306
}
290307

291308
/// Data about a request that was received and is being handled.

pkg/analysis_server/lib/src/services/correction/dart/make_final.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class MakeFinal extends CorrectionProducer {
8888
} else if (node is VariableDeclaration &&
8989
parent is VariableDeclarationList) {
9090
list = parent;
91+
} else if (node is VariableDeclarationList) {
92+
list = node;
9193
} else {
9294
return;
9395
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
6+
import 'package:analysis_server/src/services/correction/fix.dart';
7+
import 'package:analyzer/dart/ast/ast.dart';
8+
import 'package:analyzer/dart/ast/token.dart';
9+
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
10+
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
11+
import 'package:analyzer_plugin/utilities/range_factory.dart';
12+
13+
class RemoveUnnecessaryFinal extends CorrectionProducer {
14+
@override
15+
bool get canBeAppliedInBulk => true;
16+
17+
@override
18+
bool get canBeAppliedToFile => true;
19+
20+
@override
21+
FixKind get fixKind => DartFixKind.REMOVE_UNNECESSARY_FINAL;
22+
23+
@override
24+
FixKind get multiFixKind => DartFixKind.REMOVE_UNNECESSARY_FINAL_MULTI;
25+
26+
@override
27+
Future<void> compute(ChangeBuilder builder) async {
28+
var node = this.node;
29+
Token? keyword;
30+
if (node is FieldFormalParameter) {
31+
keyword = node.keyword;
32+
} else if (node is SuperFormalParameter) {
33+
keyword = node.keyword;
34+
}
35+
if (keyword == null) return;
36+
37+
await builder.addDartFileEdit(file, (builder) {
38+
builder.addDeletion(range.startStart(keyword!, keyword.next!));
39+
});
40+
}
41+
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ HintCode.UNIGNORABLE_IGNORE:
14561456
HintCode.UNNECESSARY_CAST:
14571457
status: hasFix
14581458
HintCode.UNNECESSARY_FINAL:
1459-
status: needsEvaluation
1459+
status: hasFix
14601460
HintCode.UNNECESSARY_IGNORE:
14611461
status: needsEvaluation
14621462
HintCode.UNNECESSARY_IMPORT:

pkg/analysis_server/lib/src/services/correction/fix.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,16 @@ class DartFixKind {
11281128
DartFixKindPriority.IN_FILE,
11291129
'Remove all unnecessary casts in file',
11301130
);
1131+
static const REMOVE_UNNECESSARY_FINAL = FixKind(
1132+
'dart.fix.remove.unnecessaryFinal',
1133+
DartFixKindPriority.DEFAULT,
1134+
"Remove unnecessary 'final'",
1135+
);
1136+
static const REMOVE_UNNECESSARY_FINAL_MULTI = FixKind(
1137+
'dart.fix.remove.unnecessaryFinal.multi',
1138+
DartFixKindPriority.IN_FILE,
1139+
"Remove all unnecessary 'final's in file",
1140+
);
11311141
static const REMOVE_UNNECESSARY_CONST = FixKind(
11321142
'dart.fix.remove.unnecessaryConst',
11331143
DartFixKindPriority.DEFAULT,

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ import 'package:analysis_server/src/services/correction/dart/remove_this_express
139139
import 'package:analysis_server/src/services/correction/dart/remove_type_annotation.dart';
140140
import 'package:analysis_server/src/services/correction/dart/remove_type_arguments.dart';
141141
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_cast.dart';
142+
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_final.dart';
142143
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_late.dart';
143144
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_new.dart';
144145
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_parentheses.dart';
@@ -1326,6 +1327,9 @@ class FixProcessor extends BaseProcessor {
13261327
HintCode.UNNECESSARY_CAST: [
13271328
RemoveUnnecessaryCast.new,
13281329
],
1330+
HintCode.UNNECESSARY_FINAL: [
1331+
RemoveUnnecessaryFinal.new,
1332+
],
13291333
HintCode.UNNECESSARY_IMPORT: [
13301334
RemoveUnusedImport.new,
13311335
],

pkg/analysis_server/lib/src/services/refactoring/extract_local.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
230230
}
231231
if (selectionOffset + selectionLength >= resolveResult.content.length) {
232232
return RefactoringStatus.fatal(
233-
'The selection end offset must be less then the length of the file.');
233+
'The selection end offset must be less than the length of the file.');
234234
}
235235

236236
var selectionStr = utils.getRangeText(selectionRange);

pkg/analysis_server/lib/src/services/refactoring/extract_method.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
458458
}
459459
if (selectionOffset + selectionLength >= resolveResult.content.length) {
460460
return RefactoringStatus.fatal(
461-
'The selection end offset must be less then the length of the file.');
461+
'The selection end offset must be less than the length of the file.');
462462
}
463463

464464
// Check for implicitly selected closure.
@@ -989,10 +989,19 @@ class _ExtractMethodAnalyzer extends StatementAnalyzer {
989989
if (element is FunctionElement || element is MethodElement) {
990990
invalidSelection('Cannot extract a single method name.');
991991
}
992-
// name in property access
993-
if (node.parent is PrefixedIdentifier &&
994-
(node.parent as PrefixedIdentifier).identifier == node) {
995-
invalidSelection('Can not extract name part of a property access.');
992+
var parent = node.parent;
993+
if (parent is PrefixedIdentifier) {
994+
if (parent.identifier == node) {
995+
// name in property access
996+
invalidSelection('Cannot extract name part of a property access.');
997+
} else if (parent.prefix == node && parent.parent is NamedType) {
998+
// prefix in a named type (for example `io` in `io.File`)
999+
invalidSelection('Cannot extract prefix part of a type reference.');
1000+
}
1001+
}
1002+
// part of a named type (for example `int` in `int?`)
1003+
if (node.parent is NamedType) {
1004+
invalidSelection('Cannot extract a single type reference.');
9961005
}
9971006
}
9981007
}

pkg/analysis_server/test/lsp/code_actions_refactor_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ void f() {}
364364
expect(codeAction, isNull);
365365
}
366366

367+
Future<void> test_invalidLocation_importPrefix() async {
368+
const content = '''
369+
import 'dart:io' as io;
370+
371+
i^o.File a;
372+
''';
373+
newFile(mainFilePath, withoutMarkers(content));
374+
await initialize();
375+
376+
final codeActions = await getCodeActions(mainFileUri.toString(),
377+
position: positionFromMarker(content));
378+
final codeAction =
379+
findCommand(codeActions, Commands.performRefactor, extractMethodTitle);
380+
expect(codeAction, isNull);
381+
}
382+
367383
Future<void> test_progress_clientProvided() async {
368384
const content = '''
369385
void f() {

pkg/analysis_server/test/services/refactoring/extract_method_test.dart

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void f(A a) {
438438
''');
439439
_createRefactoringWithSuffix('fff', ' = 1');
440440
return _assertConditionsFatal(
441-
'Can not extract name part of a property access.');
441+
'Cannot extract name part of a property access.');
442442
}
443443

444444
Future<void> test_bad_newMethodName_notIdentifier() async {
@@ -752,6 +752,27 @@ void f() {
752752
return _assertConditionsFatal('Cannot extract a single type reference.');
753753
}
754754

755+
Future<void> test_bad_typeReference_nullable() async {
756+
await indexTestUnit('''
757+
// Dummy comment ("The selection offset must be greater than zero")
758+
int? f;
759+
''');
760+
_createRefactoringForString('int');
761+
return _assertConditionsFatal('Cannot extract a single type reference.');
762+
}
763+
764+
Future<void> test_bad_typeReference_prefix() async {
765+
await indexTestUnit('''
766+
import 'dart:io' as io;
767+
void f() {
768+
io.File f = io.File('');
769+
}
770+
''');
771+
_createRefactoringWithSuffix('io', '.File f');
772+
return _assertConditionsFatal(
773+
'Cannot extract prefix part of a type reference.');
774+
}
775+
755776
Future<void> test_bad_variableDeclarationFragment() async {
756777
await indexTestUnit('''
757778
void f() {
@@ -1251,6 +1272,29 @@ void f() {
12511272
expect(refactoring.lengths, unorderedEquals([5, 6]));
12521273
}
12531274

1275+
Future<void> test_prefixPartOfQualified() async {
1276+
await indexTestUnit('''
1277+
class A {
1278+
var fff;
1279+
}
1280+
void f(A a) {
1281+
a.fff = 5;
1282+
}
1283+
''');
1284+
_createRefactoringForStringOffset('a.fff');
1285+
// apply refactoring
1286+
return _assertSuccessfulRefactoring('''
1287+
class A {
1288+
var fff;
1289+
}
1290+
void f(A a) {
1291+
res(a).fff = 5;
1292+
}
1293+
1294+
A res(A a) => a;
1295+
''');
1296+
}
1297+
12541298
Future<void> test_returnType_closure() async {
12551299
await indexTestUnit('''
12561300
process(f(x)) {}

0 commit comments

Comments
 (0)