From 8b29e93beae93aa790cf99c43bdebb8d61ba1cd1 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 6 May 2026 07:30:09 -0700 Subject: [PATCH] [analysis_server] Include count of additional errors in "Rename anyway?" prompt Follow up from https://dart-review.googlesource.com/c/sdk/+/499600 + fix typo + fix bug that inline_method treated required named arguments as optional instead of required Change-Id: I1c088138d990a27ed74ff51993bbe4032b245693 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500780 Reviewed-by: Brian Wilkerson Reviewed-by: Keerti Parthasarathy --- .../handlers/commands/perform_refactor.dart | 13 ++++++- .../refactoring/legacy/inline_method.dart | 2 +- .../abstract_lsp_over_legacy.dart | 2 +- .../legacy/inline_method_test.dart | 21 ++++++++++ .../shared_code_actions_refactor_tests.dart | 39 +++++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/pkg/analysis_server/lib/src/lsp/handlers/commands/perform_refactor.dart b/pkg/analysis_server/lib/src/lsp/handlers/commands/perform_refactor.dart index 71bbf5c18b9..2a9d400da57 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/commands/perform_refactor.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/commands/perform_refactor.dart @@ -93,10 +93,21 @@ class PerformRefactorCommandHandler extends AbstractRefactorCommandHandler { // server stall because this request is blocked on user-input. message.completer?.complete(); + // Show the most severe message, but also a count of others. + var promptMessage = status.message!; + var numberOfOtherErrors = status.problems.length - 1; + if (numberOfOtherErrors > 0) { + var suffix = numberOfOtherErrors == 1 + ? ' (+ 1 other error)' + : ' (+ $numberOfOtherErrors other errors)'; + + promptMessage += suffix; + } + // Ask the user whether to proceed with the refactor. var userChoice = await prompt( MessageType.warning, - status.message!, + promptMessage, [UserPromptActions.refactorAnyway, UserPromptActions.cancel], cancellationToken, ); diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart index 949d20fe0e1..c3afc920179 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart @@ -117,7 +117,7 @@ Future<_InlineMethodResult> _getMethodSourceForInvocation( argumentSource = utils.getNodeText(argument); } else { // report about a missing required parameter - if (parameter.isRequiredPositional) { + if (parameter.isRequired) { status.addError( 'No argument for the parameter "${parameter.name}".', newLocation_fromNode(contextNode), diff --git a/pkg/analysis_server/test/lsp_over_legacy/abstract_lsp_over_legacy.dart b/pkg/analysis_server/test/lsp_over_legacy/abstract_lsp_over_legacy.dart index 83b6922f794..fde0b447053 100644 --- a/pkg/analysis_server/test/lsp_over_legacy/abstract_lsp_over_legacy.dart +++ b/pkg/analysis_server/test/lsp_over_legacy/abstract_lsp_over_legacy.dart @@ -324,7 +324,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest ); var request = ServerSetClientCapabilitiesParams( [ - // Use the LSP capabilitie to determine if we show this for the legacy + // Use the LSP capabilities to determine if we show this for the legacy // protocol so that shared tests only need to set one. if (experimentalCapabilities['supportsWindowShowMessageRequest'] == true) diff --git a/pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart b/pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart index f11e4b12ab4..dad85fabfd0 100644 --- a/pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart +++ b/pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart @@ -2479,6 +2479,27 @@ void f() { ); } + Future test_noArgument_requiredNamed() async { + verifyNoTestUnitErrors = false; + await indexTestUnit(r''' +test({ required a }) { + print(a); +} +void f() { + ^[!test()!]; +} +'''); + _createRefactoring(); + // error + var status = await refactoring.checkAllConditions(); + assertRefactoringStatus( + status, + RefactoringProblemSeverity.ERROR, + expectedMessage: 'No argument for the parameter "a".', + rangeIndex: 0, + ); + } + Future test_reference_expressionBody() async { await indexTestUnit(r''' String ^message() => 'Hello, World!'; diff --git a/pkg/analysis_server/test/shared/shared_code_actions_refactor_tests.dart b/pkg/analysis_server/test/shared/shared_code_actions_refactor_tests.dart index 92e8e82c959..f4ea1b9e1ba 100644 --- a/pkg/analysis_server/test/shared/shared_code_actions_refactor_tests.dart +++ b/pkg/analysis_server/test/shared/shared_code_actions_refactor_tests.dart @@ -918,6 +918,45 @@ void f() { ); } + Future test_error_refactorAnyway_multipleErrors() async { + failTestOnErrorDiagnostic = false; + setSupportsWindowShowMessageRequest(); + + const content = ''' +void f() { + bar(); + bar(); +} + +void b^ar(int a) { + print(a); +} +'''; + const expectedContent = ''' +void f() { + print(a); + print(a); +} +'''; + + await handleRefactorAnywayPrompt( + expectedMessage: 'No argument for the parameter "a". (+ 1 other error)', + expectedActions: [ + UserPromptActions.refactorAnyway, + UserPromptActions.cancel, + ], + selectAction: UserPromptActions.refactorAnyway, + () async { + await verifyCodeActionLiteralEdits( + content, + expectedContent, + command: Commands.performRefactor, + title: inlineMethodTitle, + ); + }, + ); + } + Future test_inlineAtCallSite() async { const content = ''' void foo1() {