mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:45:06 +00:00
Prioritize required name param completions (flutter-intellij#1049).
R=danrubel@google.com Fixes: https://github.com/flutter/flutter-intellij/issues/1049 Review-Url: https://codereview.chromium.org/2927343002 .
This commit is contained in:
parent
0e6586492d
commit
b502bb6956
|
@ -254,9 +254,14 @@ class ArgListContributor extends DartCompletionContributor {
|
|||
if (appendComma) {
|
||||
completion += ',';
|
||||
}
|
||||
|
||||
final int relevance = parameter.isRequired
|
||||
? DART_RELEVANCE_NAMED_PARAMETER_REQUIRED
|
||||
: DART_RELEVANCE_NAMED_PARAMETER;
|
||||
|
||||
CompletionSuggestion suggestion = new CompletionSuggestion(
|
||||
CompletionSuggestionKind.NAMED_ARGUMENT,
|
||||
DART_RELEVANCE_NAMED_PARAMETER,
|
||||
relevance,
|
||||
completion,
|
||||
selectionOffset,
|
||||
0,
|
||||
|
|
|
@ -95,9 +95,11 @@ class ArgListContributorTest extends DartCompletionContributorTest {
|
|||
*/
|
||||
void assertSuggestArgumentsAndTypes(
|
||||
{Map<String, String> namedArgumentsWithTypes,
|
||||
List<int> requiredParamIndices: const <int>[],
|
||||
bool includeColon: true,
|
||||
bool includeComma: false}) {
|
||||
List<CompletionSuggestion> expected = new List<CompletionSuggestion>();
|
||||
int paramIndex = 0;
|
||||
namedArgumentsWithTypes.forEach((String name, String type) {
|
||||
String completion = includeColon ? '$name: ' : name;
|
||||
// Selection should be before any trailing commas.
|
||||
|
@ -105,9 +107,12 @@ class ArgListContributorTest extends DartCompletionContributorTest {
|
|||
if (includeComma) {
|
||||
completion = '$completion,';
|
||||
}
|
||||
int relevance = requiredParamIndices.contains(paramIndex++)
|
||||
? DART_RELEVANCE_NAMED_PARAMETER_REQUIRED
|
||||
: DART_RELEVANCE_NAMED_PARAMETER;
|
||||
expected.add(assertSuggest(completion,
|
||||
csKind: CompletionSuggestionKind.NAMED_ARGUMENT,
|
||||
relevance: DART_RELEVANCE_NAMED_PARAMETER,
|
||||
relevance: relevance,
|
||||
paramName: name,
|
||||
paramType: type,
|
||||
selectionOffset: selectionOffset));
|
||||
|
@ -863,6 +868,18 @@ main() { new A(^, two: 'foo');}''');
|
|||
completion: 'one: ', selectionOffset: 5);
|
||||
}
|
||||
|
||||
test_ArgumentList_local_constructor_required_param_0() async {
|
||||
addMetaPackageSource();
|
||||
addTestSource('''
|
||||
import 'package:meta/meta.dart';
|
||||
class A { A({int one, @required String two: 'defaultValue'}) { } }
|
||||
main() { new A(^);}''');
|
||||
await computeSuggestions();
|
||||
assertSuggestArgumentsAndTypes(
|
||||
namedArgumentsWithTypes: {'one': 'int', 'two': 'String'},
|
||||
requiredParamIndices: [1]);
|
||||
}
|
||||
|
||||
test_ArgumentList_local_function_1() async {
|
||||
// ArgumentList MethodInvocation ExpressionStatement Block
|
||||
addTestSource('''
|
||||
|
|
|
@ -23,4 +23,5 @@ const int DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE = 1056;
|
|||
const int DART_RELEVANCE_LOCAL_VARIABLE = 1059;
|
||||
const int DART_RELEVANCE_LOW = 500;
|
||||
const int DART_RELEVANCE_NAMED_PARAMETER = 1060;
|
||||
const int DART_RELEVANCE_NAMED_PARAMETER_REQUIRED = 1065;
|
||||
const int DART_RELEVANCE_PARAMETER = 1059;
|
||||
|
|
Loading…
Reference in a new issue