[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 <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
This commit is contained in:
Danny Tuppeny
2026-05-06 07:30:09 -07:00
committed by Brian Wilkerson
parent 9514710249
commit 8b29e93bea
5 changed files with 74 additions and 3 deletions
@@ -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,
);
@@ -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),
@@ -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)
@@ -2479,6 +2479,27 @@ void f() {
);
}
Future<void> 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<void> test_reference_expressionBody() async {
await indexTestUnit(r'''
String ^message() => 'Hello, World!';
@@ -918,6 +918,45 @@ void f() {
);
}
Future<void> 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<void> test_inlineAtCallSite() async {
const content = '''
void foo1() {