@@ -12,6 +12,7 @@ import 'package:analysis_server/src/protocol_server.dart'
12
12
hide AnalysisOptions, Position;
13
13
import 'package:analysis_server/src/services/correction/assist.dart' ;
14
14
import 'package:analysis_server/src/services/correction/fix_performance.dart' ;
15
+ import 'package:analysis_server/src/services/correction/refactoring_performance.dart' ;
15
16
import 'package:analysis_server/src/services/refactoring/framework/refactoring_context.dart' ;
16
17
import 'package:analysis_server/src/services/refactoring/framework/refactoring_processor.dart' ;
17
18
import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart' ;
@@ -264,14 +265,17 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
264
265
}
265
266
266
267
@override
267
- Future <List <Either2 <CodeAction , Command >>> getRefactorActions () async {
268
+ Future <List <Either2 <CodeAction , Command >>> getRefactorActions (
269
+ OperationPerformance ? performance,
270
+ ) async {
268
271
// If the client does not support workspace/applyEdit, we won't be able to
269
272
// run any of these.
270
273
if (! supportsApplyEdit) {
271
274
return const [];
272
275
}
273
276
274
277
var refactorActions = < Either2 <CodeAction , Command >> [];
278
+ var performanceTracker = RefactoringPerformance ();
275
279
276
280
try {
277
281
// New interactive refactors.
@@ -286,12 +290,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
286
290
includeExperimental:
287
291
server.lspClientConfiguration.global.experimentalRefactors,
288
292
);
289
- var processor = RefactoringProcessor (context);
293
+ var processor = RefactoringProcessor (
294
+ context,
295
+ performance: performanceTracker,
296
+ );
290
297
var actions = await processor.compute ();
291
298
refactorActions.addAll (actions.map (Either2 <CodeAction , Command >.t1));
292
299
293
300
// Extracts
294
301
if (shouldIncludeKind (CodeActionKind .RefactorExtract )) {
302
+ var timer = Stopwatch ()..start ();
295
303
// Extract Method
296
304
if (ExtractMethodRefactoring (
297
305
server.searchEngine,
@@ -307,6 +315,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
307
315
),
308
316
);
309
317
}
318
+ performanceTracker.addTiming (
319
+ className: 'ExtractMethodRefactoring' ,
320
+ timer: timer,
321
+ );
310
322
311
323
// Extract Local Variable
312
324
if (ExtractLocalRefactoring (unitResult, offset, length).isAvailable ()) {
@@ -318,6 +330,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
318
330
),
319
331
);
320
332
}
333
+ performanceTracker.addTiming (
334
+ className: 'ExtractLocalRefactoring' ,
335
+ timer: timer,
336
+ );
321
337
322
338
// Extract Widget
323
339
if (ExtractWidgetRefactoring (
@@ -334,10 +350,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
334
350
),
335
351
);
336
352
}
353
+ performanceTracker.addTiming (
354
+ className: 'ExtractWidgetRefactoring' ,
355
+ timer: timer,
356
+ );
337
357
}
338
358
359
+ var timer = Stopwatch ();
339
360
// Inlines
340
361
if (shouldIncludeKind (CodeActionKind .RefactorInline )) {
362
+ timer.start ();
341
363
// Inline Local Variable
342
364
if (InlineLocalRefactoring (
343
365
server.searchEngine,
@@ -352,6 +374,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
352
374
),
353
375
);
354
376
}
377
+ performanceTracker.addTiming (
378
+ className: 'InlineLocalRefactoring' ,
379
+ timer: timer,
380
+ );
355
381
356
382
// Inline Method
357
383
if (InlineMethodRefactoring (
@@ -367,10 +393,16 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
367
393
),
368
394
);
369
395
}
396
+ performanceTracker.addTiming (
397
+ className: 'InlineMethodRefactoring' ,
398
+ timer: timer,
399
+ );
370
400
}
371
401
372
402
// Converts/Rewrites
373
403
if (shouldIncludeKind (CodeActionKind .RefactorRewrite )) {
404
+ timer.restart ();
405
+
374
406
var node = NodeLocator (offset).searchWithin (unitResult.unit);
375
407
var element = server.getElementOfNode (node);
376
408
@@ -389,6 +421,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
389
421
),
390
422
);
391
423
}
424
+ performanceTracker.addTiming (
425
+ className: 'ConvertGetterToMethodRefactoring' ,
426
+ timer: timer,
427
+ );
392
428
393
429
// Method to Getter
394
430
if (element is ExecutableElement2 &&
@@ -405,6 +441,22 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
405
441
),
406
442
);
407
443
}
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
+ );
408
460
}
409
461
410
462
return refactorActions;
@@ -457,3 +509,20 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
457
509
: Either2 <CodeAction , Command >.t2 (command);
458
510
}
459
511
}
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
+ }
0 commit comments