mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 13:18:09 +00:00
Update CompletionWithSuggestionsTest for better alignment with the new protocol.
A few tests added, mostly removing CompletionSuggestionKind.INVOCATION because it is set just for any available declaration by the completion driver, but this is not what we use for local elements and the new protocol. Change-Id: I87da134fd94da75005a98e17e81f43ee56451baf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229261 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
025b67f48c
commit
8781ab0151
|
@ -155,7 +155,7 @@ protocol.ElementKind protocolElementKind(DeclarationKind kind) {
|
|||
case DeclarationKind.FUNCTION:
|
||||
return protocol.ElementKind.FUNCTION;
|
||||
case DeclarationKind.FUNCTION_TYPE_ALIAS:
|
||||
return protocol.ElementKind.FUNCTION_TYPE_ALIAS;
|
||||
return protocol.ElementKind.TYPE_ALIAS;
|
||||
case DeclarationKind.GETTER:
|
||||
return protocol.ElementKind.GETTER;
|
||||
case DeclarationKind.METHOD:
|
||||
|
|
|
@ -132,7 +132,9 @@ abstract class AbstractCompletionDriverTest with ResourceProviderMixin {
|
|||
);
|
||||
await driver.createProject(packageRoots: packageRoots);
|
||||
|
||||
newPubspecYamlFile(projectPath, '');
|
||||
newPubspecYamlFile(projectPath, '''
|
||||
name: project
|
||||
''');
|
||||
newDotPackagesFile(projectPath, content: '''
|
||||
project:${toUri('$projectPath/lib')}
|
||||
''');
|
||||
|
@ -279,9 +281,9 @@ void f() {
|
|||
}
|
||||
''');
|
||||
assertSuggestion(
|
||||
completion: 'E.e',
|
||||
element: ElementKind.ENUM_CONSTANT,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'E.e',
|
||||
element: ElementKind.ENUM_CONSTANT,
|
||||
);
|
||||
}
|
||||
|
||||
/// See: https://github.com/dart-lang/sdk/issues/40620
|
||||
|
@ -327,9 +329,9 @@ void f() {
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_project_lib() async {
|
||||
|
@ -356,33 +358,33 @@ void f() {
|
|||
element: ElementKind.CONSTRUCTOR,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
assertSuggestion(
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'E',
|
||||
element: ElementKind.ENUM,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'E',
|
||||
element: ElementKind.ENUM,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'Ex',
|
||||
element: ElementKind.EXTENSION,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'Ex',
|
||||
element: ElementKind.EXTENSION,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'M',
|
||||
element: ElementKind.MIXIN,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'M',
|
||||
element: ElementKind.MIXIN,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'T',
|
||||
element: ElementKind.FUNCTION_TYPE_ALIAS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'T',
|
||||
element: ElementKind.TYPE_ALIAS,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'T2',
|
||||
element: ElementKind.TYPE_ALIAS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'T2',
|
||||
element: ElementKind.TYPE_ALIAS,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'v',
|
||||
element: ElementKind.TOP_LEVEL_VARIABLE,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'v',
|
||||
element: ElementKind.TOP_LEVEL_VARIABLE,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_project_lib_fields_class() async {
|
||||
|
@ -415,9 +417,9 @@ void f() {
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 'A.f',
|
||||
element: ElementKind.FIELD,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'A.f',
|
||||
element: ElementKind.FIELD,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_project_lib_getters_class() async {
|
||||
|
@ -450,9 +452,9 @@ void f() {
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 'A.g',
|
||||
element: ElementKind.GETTER,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'A.g',
|
||||
element: ElementKind.GETTER,
|
||||
);
|
||||
}
|
||||
|
||||
/// See: https://github.com/dart-lang/sdk/issues/40626
|
||||
|
@ -468,9 +470,41 @@ void f() {
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 'g',
|
||||
element: ElementKind.GETTER,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'g',
|
||||
element: ElementKind.GETTER,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_project_lib_methods_class() async {
|
||||
await addProjectFile('lib/a.dart', r'''
|
||||
class A {
|
||||
void foo() => 0;
|
||||
}
|
||||
''');
|
||||
|
||||
await addTestFile('''
|
||||
void f() {
|
||||
^
|
||||
}
|
||||
''');
|
||||
|
||||
assertNoSuggestion(completion: 'A.foo');
|
||||
}
|
||||
|
||||
Future<void> test_project_lib_methods_static() async {
|
||||
await addProjectFile('lib/a.dart', r'''
|
||||
class A {
|
||||
static void foo() => 0;
|
||||
}
|
||||
''');
|
||||
|
||||
await addTestFile('''
|
||||
void f() {
|
||||
^
|
||||
}
|
||||
''');
|
||||
|
||||
assertNoSuggestion(completion: 'A.foo');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
|
@ -541,9 +575,9 @@ void f() {
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 's',
|
||||
element: ElementKind.SETTER,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 's',
|
||||
element: ElementKind.SETTER,
|
||||
);
|
||||
}
|
||||
|
||||
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38739')
|
||||
|
@ -596,16 +630,17 @@ void f(List<String> args) {
|
|||
''');
|
||||
|
||||
expect(
|
||||
suggestionWith(
|
||||
completion: 'A',
|
||||
element: ElementKind.CONSTRUCTOR,
|
||||
).relevance,
|
||||
greaterThan(
|
||||
suggestionWith(
|
||||
completion: 'A',
|
||||
element: ElementKind.CONSTRUCTOR,
|
||||
kind: CompletionSuggestionKind.INVOCATION)
|
||||
.relevance,
|
||||
greaterThan(suggestionWith(
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
kind: CompletionSuggestionKind.INVOCATION)
|
||||
.relevance));
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
).relevance,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// See: https://github.com/dart-lang/sdk/issues/35529
|
||||
|
@ -620,13 +655,13 @@ class C extends Object with ^
|
|||
''');
|
||||
|
||||
assertSuggestion(
|
||||
completion: 'M',
|
||||
element: ElementKind.MIXIN,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'M',
|
||||
element: ElementKind.MIXIN,
|
||||
);
|
||||
assertSuggestion(
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'A',
|
||||
element: ElementKind.CLASS,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_sdk_lib_future_isNotDuplicated() async {
|
||||
|
@ -682,17 +717,17 @@ void f() {
|
|||
|
||||
// + Classes.
|
||||
assertSuggestion(
|
||||
completion: 'HashMap',
|
||||
file: '/sdk/lib/collection/collection.dart',
|
||||
element: ElementKind.CLASS,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'HashMap',
|
||||
file: '/sdk/lib/collection/collection.dart',
|
||||
element: ElementKind.CLASS,
|
||||
);
|
||||
|
||||
// + Top level variables.
|
||||
assertSuggestion(
|
||||
completion: 'pi',
|
||||
file: '/sdk/lib/math/math.dart',
|
||||
element: ElementKind.TOP_LEVEL_VARIABLE,
|
||||
kind: CompletionSuggestionKind.INVOCATION);
|
||||
completion: 'pi',
|
||||
file: '/sdk/lib/math/math.dart',
|
||||
element: ElementKind.TOP_LEVEL_VARIABLE,
|
||||
);
|
||||
|
||||
// (No typedefs, enums, extensions defined in the Mock SDK.)
|
||||
}
|
||||
|
|
|
@ -130,6 +130,20 @@ class CompletionDriver extends AbstractClient with ExpectMixin {
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
Future<List<CompletionSuggestion>> getSuggestions2() async {
|
||||
await waitForTasksFinished();
|
||||
|
||||
var request = CompletionGetSuggestions2Params(
|
||||
testFilePath,
|
||||
completionOffset,
|
||||
1 << 16,
|
||||
timeout: 60 * 1000,
|
||||
).toRequest('0');
|
||||
var response = await waitResponse(request);
|
||||
var result = CompletionGetSuggestions2Result.fromResponse(response);
|
||||
return result.suggestions;
|
||||
}
|
||||
|
||||
@override
|
||||
File newFile(String path, String content) =>
|
||||
resourceProvider.newFile(resourceProvider.convertPath(path), content);
|
||||
|
|
|
@ -519,7 +519,7 @@ typedef MyAlias = void Function();
|
|||
"label": "MyAlias",
|
||||
"declaringLibraryUri": "package:test/a.dart",
|
||||
"element": {
|
||||
"kind": "FUNCTION_TYPE_ALIAS",
|
||||
"kind": "TYPE_ALIAS",
|
||||
"name": "MyAlias",
|
||||
"location": {
|
||||
"file": ${jsonOfPath(path)},
|
||||
|
|
|
@ -66,6 +66,9 @@ abstract class Completer<T> {
|
|||
}
|
||||
|
||||
abstract class Timer {
|
||||
factory Timer(Duration duration, void Function() callback) {
|
||||
throw 0;
|
||||
}
|
||||
static void run(void callback()) {}
|
||||
}
|
||||
''',
|
||||
|
|
Loading…
Reference in a new issue