diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_super_parameters.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_super_parameters.dart index 02af29ecbfb..5f7e010cd0b 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_super_parameters.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_super_parameters.dart @@ -67,7 +67,8 @@ class ConvertToSuperParameters extends CorrectionProducer { var parameterMap = _parameterMap(constructor.parameters); List<_ParameterData>? positional = []; var named = <_ParameterData>[]; - var arguments = superInvocation.argumentList.arguments; + var argumentList = superInvocation.argumentList; + var arguments = argumentList.arguments; for (var argumentIndex = 0; argumentIndex < arguments.length; argumentIndex++) { @@ -156,18 +157,26 @@ class ConvertToSuperParameters extends CorrectionProducer { } // Remove the corresponding arguments. - if (argumentsToDelete.length == arguments.length && - superInvocation.constructorName == null) { - var initializers = constructor.initializers; - SourceRange initializerRange; - if (initializers.length == 1) { - initializerRange = - range.endEnd(constructor.parameters, superInvocation); + if (argumentsToDelete.length == arguments.length) { + if (superInvocation.constructorName == null) { + // Delete the whole invocation. + var initializers = constructor.initializers; + SourceRange initializerRange; + if (initializers.length == 1) { + initializerRange = + range.endEnd(constructor.parameters, superInvocation); + } else { + initializerRange = range.nodeInList(initializers, superInvocation); + } + builder.addDeletion(initializerRange); } else { - initializerRange = range.nodeInList(initializers, superInvocation); + // Leave the invocation, but remove all of the arguments, including + // any trailing comma. + builder.addDeletion(range.endStart( + argumentList.leftParenthesis, argumentList.rightParenthesis)); } - builder.addDeletion(initializerRange); } else { + // Remove just the arguments that are no longer needed. var ranges = range.nodesInList(arguments, argumentsToDelete); for (var range in ranges) { builder.addDeletion(range); diff --git a/pkg/analysis_server/test/src/services/correction/assist/convert_to_super_parameters_test.dart b/pkg/analysis_server/test/src/services/correction/assist/convert_to_super_parameters_test.dart index 987a0bdb0b7..1bf7f7491c8 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/convert_to_super_parameters_test.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/convert_to_super_parameters_test.dart @@ -733,6 +733,25 @@ class A { class B extends A { B(super.x); } +'''); + } + + Future test_trailingComma() async { + await resolveTestCode(''' +class A { + A._(int x, int y); +} +class B extends A { + B(int x, int y) : super._(x, y,); +} +'''); + await assertHasAssistAt('B(', ''' +class A { + A._(int x, int y); +} +class B extends A { + B(super.x, super.y) : super._(); +} '''); } }