Suggest named arguments anywhere when named_arguments_anywhere.

Change-Id: I1aefd0c7f4c4e140e5505a2b91a65a8c3b1e449a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222080
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-12-06 21:41:31 +00:00
parent 76bfec126d
commit 0d98f6ab5d
2 changed files with 22 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:analysis_server/src/utilities/flutter.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element.dart';
@ -100,7 +101,9 @@ class ArgListContributor extends DartCompletionContributor {
if (_isEditingNamedArgLabel() ||
_isAppendingToArgList() ||
_isAddingLabelToPositional()) {
if (requiredCount == 0 || requiredCount < _argCount()) {
if (request.featureSet.isEnabled(Feature.named_arguments_anywhere) ||
requiredCount == 0 ||
requiredCount < _argCount()) {
// If there's a replacement range that starts at the caret, it will be
// for an identifier that is not the named label and therefore it should
// not be replaced.

View file

@ -172,6 +172,15 @@ class A { const A({int one, String two: 'defaultValue'}); }
assertSuggestArgumentsAndTypes(namedArgumentsWithTypes: {'one': 'int'});
}
Future<void> test_Annotation_local_constructor_named_param_12() async {
addTestSource('''
class A { const A(int one, int two, int three, {int four, String five:
'defaultValue'}); }
@A(1, ^, 3) main() { }''');
await computeSuggestions();
assertSuggestions(['four: ', 'five: ']);
}
Future<void> test_Annotation_local_constructor_named_param_2() async {
addTestSource('''
class A { const A({int one, String two: 'defaultValue'}); }
@ -239,6 +248,7 @@ class A { const A({int one, String two: 'defaultValue'}); }
Future<void> test_Annotation_local_constructor_named_param_negative() async {
addTestSource('''
// @dart = 2.15
class A { const A(int one, int two, int three, {int four, String five:
'defaultValue'}); }
@A(1, ^, 3) main() { }''');
@ -660,6 +670,7 @@ foo({String children}) {}
expect(String arg1, int arg2, {bool arg3}) { }
void baz() { }''');
addTestSource('''
// @dart = 2.15
import 'a.dart'
class B { }
String bar() => true;
@ -676,6 +687,7 @@ foo({String children}) {}
expect(String arg1, int arg2, {bool arg3}) { }
void baz() { }''');
addTestSource('''
// @dart = 2.15
import 'a.dart'
class B { }
String bar() => true;
@ -692,6 +704,7 @@ foo({String children}) {}
expect(String arg1, int arg2, {bool arg3}) { }
void baz() { }''');
addTestSource('''
// @dart = 2.15
import 'a.dart'
class B { }
String bar() => true;
@ -708,6 +721,7 @@ foo({String children}) {}
expect(String arg1, int arg2, {bool arg3}) { }
void baz() { }''');
addTestSource('''
// @dart = 2.15
import 'a.dart'
class B { }
String bar() => true;
@ -987,6 +1001,7 @@ main() { new A(^);}''');
Future<void> test_ArgumentList_local_function_3a() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addTestSource('''
// @dart = 2.15
expect(arg1, int arg2, {bool arg3}) { }
class B { }
String bar() => true;
@ -998,6 +1013,7 @@ main() { new A(^);}''');
Future<void> test_ArgumentList_local_function_3b() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addTestSource('''
// @dart = 2.15
expect(arg1, int arg2, {bool arg3}) { }
class B { }
String bar() => true;
@ -1009,6 +1025,7 @@ main() { new A(^);}''');
Future<void> test_ArgumentList_local_function_3c() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addTestSource('''
// @dart = 2.15
expect(arg1, int arg2, {bool arg3}) { }
class B { }
String bar() => true;
@ -1020,6 +1037,7 @@ main() { new A(^);}''');
Future<void> test_ArgumentList_local_function_3d() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addTestSource('''
// @dart = 2.15
expect(arg1, int arg2, {bool arg3}) { }
class B { }
String bar() => true;