Skip to content

Commit 0474c9f

Browse files
author
Dart CI
committedMar 21, 2025
Version 3.8.0-214.0.dev
Merge ae6da8b into dev
2 parents 86f64ac + ae6da8b commit 0474c9f

File tree

20 files changed

+271
-82
lines changed

20 files changed

+271
-82
lines changed
 

‎DEPS

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ vars = {
130130
# 'tools/rev_sdk_deps.dart' will rev pkg dependencies to their latest; put an
131131
# EOL comment after a dependency to instead pin at the current revision.
132132
"core_rev": "61e677100b06d56a1b3731ab1178ebf9102ecb1f",
133-
"dartdoc_rev": "c41b86b98ca935ec3c29cdb04cb190df30afb242",
134-
"ecosystem_rev": "5b8e6b8973663a64be5b98159da51409267a685b",
133+
"dartdoc_rev": "d40067626b8c419e451897447e4dae74d25bcc37",
134+
"ecosystem_rev": "23172636e60c52384b40e6bd1240d12c8e860122",
135135
"flute_rev": "e4ea0459a7debae5e9592c85141707b01fac86c9",
136-
"http_rev": "9129a96be871a5779436f042bd13790960171373",
136+
"http_rev": "1b6e28d7e1c61f7b0f8561be7aee9c35b03de193",
137137
"i18n_rev": "d9cce0b6348b51872fb269e43ff8a43120fe191d",
138138
"leak_tracker_rev": "f5620600a5ce1c44f65ddaa02001e200b096e14c", # rolled manually
139139
"material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e",

‎pkg/analysis_server/lib/src/analysis_server.dart

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import 'package:analysis_server/src/server/message_scheduler.dart';
3232
import 'package:analysis_server/src/services/completion/completion_performance.dart';
3333
import 'package:analysis_server/src/services/correction/fix_performance.dart';
3434
import 'package:analysis_server/src/services/correction/namespace.dart';
35+
import 'package:analysis_server/src/services/correction/refactoring_performance.dart';
3536
import 'package:analysis_server/src/services/dart_tooling_daemon/dtd_services.dart';
3637
import 'package:analysis_server/src/services/pub/pub_api.dart';
3738
import 'package:analysis_server/src/services/pub/pub_command.dart';
@@ -1223,6 +1224,11 @@ class ServerRecentPerformance {
12231224
final RecentBuffer<GetFixesPerformance> getFixes =
12241225
RecentBuffer<GetFixesPerformance>(performanceListMaxLength);
12251226

1227+
/// A list of performance measurements for the latest requests to get refactorings
1228+
/// up to [performanceListMaxLength] measurements.
1229+
final RecentBuffer<GetRefactoringsPerformance> getRefactorings =
1230+
RecentBuffer<GetRefactoringsPerformance>(performanceListMaxLength);
1231+
12261232
/// A [RecentBuffer] for performance information about the most recent
12271233
/// requests.
12281234
final RecentBuffer<RequestPerformance> requests = RecentBuffer(

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ abstract class AbstractCodeActionsProducer
180180
OperationPerformance? performance,
181181
);
182182

183-
Future<List<Either2<CodeAction, Command>>> getRefactorActions();
183+
Future<List<Either2<CodeAction, Command>>> getRefactorActions(
184+
OperationPerformance? performance,
185+
);
184186

185187
Future<List<Either2<CodeAction, Command>>> getSourceActions();
186188

‎pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class AnalysisOptionsCodeActionsProducer extends AbstractCodeActionsProducer {
111111
}
112112

113113
@override
114-
Future<List<Either2<CodeAction, Command>>> getRefactorActions() async => [];
114+
Future<List<Either2<CodeAction, Command>>> getRefactorActions(
115+
OperationPerformance? performance,
116+
) async => [];
115117

116118
@override
117119
Future<List<Either2<CodeAction, Command>>> getSourceActions() async => [];

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

+71-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:analysis_server/src/protocol_server.dart'
1212
hide AnalysisOptions, Position;
1313
import 'package:analysis_server/src/services/correction/assist.dart';
1414
import 'package:analysis_server/src/services/correction/fix_performance.dart';
15+
import 'package:analysis_server/src/services/correction/refactoring_performance.dart';
1516
import 'package:analysis_server/src/services/refactoring/framework/refactoring_context.dart';
1617
import 'package:analysis_server/src/services/refactoring/framework/refactoring_processor.dart';
1718
import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart';
@@ -264,14 +265,17 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
264265
}
265266

266267
@override
267-
Future<List<Either2<CodeAction, Command>>> getRefactorActions() async {
268+
Future<List<Either2<CodeAction, Command>>> getRefactorActions(
269+
OperationPerformance? performance,
270+
) async {
268271
// If the client does not support workspace/applyEdit, we won't be able to
269272
// run any of these.
270273
if (!supportsApplyEdit) {
271274
return const [];
272275
}
273276

274277
var refactorActions = <Either2<CodeAction, Command>>[];
278+
var performanceTracker = RefactoringPerformance();
275279

276280
try {
277281
// New interactive refactors.
@@ -286,12 +290,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
286290
includeExperimental:
287291
server.lspClientConfiguration.global.experimentalRefactors,
288292
);
289-
var processor = RefactoringProcessor(context);
293+
var processor = RefactoringProcessor(
294+
context,
295+
performance: performanceTracker,
296+
);
290297
var actions = await processor.compute();
291298
refactorActions.addAll(actions.map(Either2<CodeAction, Command>.t1));
292299

293300
// Extracts
294301
if (shouldIncludeKind(CodeActionKind.RefactorExtract)) {
302+
var timer = Stopwatch()..start();
295303
// Extract Method
296304
if (ExtractMethodRefactoring(
297305
server.searchEngine,
@@ -307,6 +315,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
307315
),
308316
);
309317
}
318+
performanceTracker.addTiming(
319+
className: 'ExtractMethodRefactoring',
320+
timer: timer,
321+
);
310322

311323
// Extract Local Variable
312324
if (ExtractLocalRefactoring(unitResult, offset, length).isAvailable()) {
@@ -318,6 +330,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
318330
),
319331
);
320332
}
333+
performanceTracker.addTiming(
334+
className: 'ExtractLocalRefactoring',
335+
timer: timer,
336+
);
321337

322338
// Extract Widget
323339
if (ExtractWidgetRefactoring(
@@ -334,10 +350,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
334350
),
335351
);
336352
}
353+
performanceTracker.addTiming(
354+
className: 'ExtractWidgetRefactoring',
355+
timer: timer,
356+
);
337357
}
338358

359+
var timer = Stopwatch();
339360
// Inlines
340361
if (shouldIncludeKind(CodeActionKind.RefactorInline)) {
362+
timer.start();
341363
// Inline Local Variable
342364
if (InlineLocalRefactoring(
343365
server.searchEngine,
@@ -352,6 +374,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
352374
),
353375
);
354376
}
377+
performanceTracker.addTiming(
378+
className: 'InlineLocalRefactoring',
379+
timer: timer,
380+
);
355381

356382
// Inline Method
357383
if (InlineMethodRefactoring(
@@ -367,10 +393,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
367393
),
368394
);
369395
}
396+
performanceTracker.addTiming(
397+
className: 'InlineMethodRefactoring',
398+
timer: timer,
399+
);
370400
}
371401

372402
// Converts/Rewrites
373403
if (shouldIncludeKind(CodeActionKind.RefactorRewrite)) {
404+
timer.restart();
405+
374406
var node = NodeLocator(offset).searchWithin(unitResult.unit);
375407
var element = server.getElementOfNode(node);
376408

@@ -389,6 +421,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
389421
),
390422
);
391423
}
424+
performanceTracker.addTiming(
425+
className: 'ConvertGetterToMethodRefactoring',
426+
timer: timer,
427+
);
392428

393429
// Method to Getter
394430
if (element is ExecutableElement2 &&
@@ -405,6 +441,22 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
405441
),
406442
);
407443
}
444+
performanceTracker.addTiming(
445+
className: 'ConvertMethodToGetterRefactoring',
446+
timer: timer,
447+
);
448+
}
449+
if (performance != null) {
450+
server.recentPerformance.getRefactorings.add(
451+
GetRefactoringsPerformance(
452+
performance: performance,
453+
path: path,
454+
content: unitResult.content,
455+
offset: offset,
456+
requestLatency: performanceTracker.computeTime!.inMilliseconds,
457+
producerTimings: performanceTracker.producerTimings,
458+
),
459+
);
408460
}
409461

410462
return refactorActions;
@@ -457,3 +509,20 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
457509
: Either2<CodeAction, Command>.t2(command);
458510
}
459511
}
512+
513+
extension on Stopwatch {
514+
void restart() {
515+
reset();
516+
start();
517+
}
518+
}
519+
520+
extension on RefactoringPerformance {
521+
void addTiming({required String className, required Stopwatch timer}) {
522+
producerTimings.add((
523+
className: 'InlineMethodRefactoring',
524+
elapsedTime: timer.elapsedMilliseconds,
525+
));
526+
timer.restart();
527+
}
528+
}

‎pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class PluginCodeActionsProducer extends AbstractCodeActionsProducer {
7171
}
7272

7373
@override
74-
Future<List<Either2<CodeAction, Command>>> getRefactorActions() async => [];
74+
Future<List<Either2<CodeAction, Command>>> getRefactorActions(
75+
OperationPerformance? performance,
76+
) async => [];
7577

7678
@override
7779
Future<List<Either2<CodeAction, Command>>> getSourceActions() async => [];

‎pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class PubspecCodeActionsProducer extends AbstractCodeActionsProducer {
9797
}
9898

9999
@override
100-
Future<List<Either2<CodeAction, Command>>> getRefactorActions() async => [];
100+
Future<List<Either2<CodeAction, Command>>> getRefactorActions(
101+
OperationPerformance? performance,
102+
) async => [];
101103

102104
@override
103105
Future<List<Either2<CodeAction, Command>>> getSourceActions() async => [];

‎pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class CodeActionHandler
256256
for (var computer in actionComputers)
257257
...await performance.runAsync(
258258
'${computer.name}.getRefactorActions',
259-
(_) => computer.getRefactorActions(),
259+
(_) => computer.getRefactorActions(message.performance),
260260
),
261261
];
262262

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025, 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_plugin/src/correction/performance.dart';
6+
7+
/// Overall performance of a request for refactorings operation.
8+
class GetRefactoringsPerformance extends ProducerRequestPerformance {
9+
GetRefactoringsPerformance({
10+
required super.performance,
11+
required super.path,
12+
super.requestLatency,
13+
required super.content,
14+
required super.offset,
15+
required super.producerTimings,
16+
}) : super(operation: 'GetRefactorings');
17+
}
18+
19+
/// A callback for recording refactoring request timings.
20+
class RefactoringPerformance {
21+
Duration? computeTime;
22+
List<ProducerTiming> producerTimings = [];
23+
}

‎pkg/analysis_server/lib/src/services/refactoring/framework/refactoring_processor.dart

+20-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/src/lsp/constants.dart';
6+
import 'package:analysis_server/src/services/correction/refactoring_performance.dart';
67
import 'package:analysis_server/src/services/refactoring/convert_all_formal_parameters_to_named.dart';
78
import 'package:analysis_server/src/services/refactoring/convert_selected_formal_parameters_to_named.dart';
89
import 'package:analysis_server/src/services/refactoring/framework/refactoring_context.dart';
@@ -30,11 +31,17 @@ class RefactoringProcessor {
3031
/// The context in which the refactorings could be applied.
3132
final RefactoringContext context;
3233

33-
RefactoringProcessor(this.context);
34+
final RefactoringPerformance? _performance;
35+
36+
final Stopwatch _timer = Stopwatch();
37+
38+
RefactoringProcessor(this.context, {RefactoringPerformance? performance})
39+
: _performance = performance;
3440

3541
/// Return a list containing one code action for each of the refactorings that
3642
/// are available in the current context.
3743
Future<List<CodeAction>> compute() async {
44+
_timer.start();
3845
var refactorings = <CodeAction>[];
3946
for (var entry in RefactoringProcessor.generators.entries) {
4047
var generator = entry.value;
@@ -43,9 +50,14 @@ class RefactoringProcessor {
4350
if (producer.isExperimental && !context.includeExperimental) {
4451
continue;
4552
}
46-
53+
var startTime = _timer.elapsedMilliseconds;
4754
var isAvailable = producer.isAvailable();
4855
if (!isAvailable) {
56+
// Track time checking for availablity before continuing.
57+
_performance?.producerTimings.add((
58+
className: producer.runtimeType.toString(),
59+
elapsedTime: _timer.elapsedMilliseconds - startTime,
60+
));
4961
continue;
5062
}
5163

@@ -90,7 +102,13 @@ class RefactoringProcessor {
90102
data: {'parameters': parameters},
91103
),
92104
);
105+
_performance?.producerTimings.add((
106+
className: producer.runtimeType.toString(),
107+
elapsedTime: _timer.elapsedMilliseconds - startTime,
108+
));
93109
}
110+
_timer.stop();
111+
_performance?.computeTime = _timer.elapsed;
94112
return refactorings;
95113
}
96114
}

0 commit comments

Comments
 (0)
Failed to load comments.