From 8781ab0151888a4b9eef50f0777d0a0908166d05 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 20 Jan 2022 22:44:08 +0000 Subject: [PATCH] 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 Commit-Queue: Konstantin Shcheglov --- .../completion/available_suggestions.dart | 2 +- .../test/client/completion_driver_test.dart | 161 +++++++++++------- .../test/client/impl/completion_driver.dart | 14 ++ .../available_suggestion_sets_test.dart | 2 +- .../lib/src/test_utilities/mock_sdk.dart | 3 + 5 files changed, 117 insertions(+), 65 deletions(-) diff --git a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart index e8838cea827..3c7bbac3264 100644 --- a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart +++ b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart @@ -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: diff --git a/pkg/analysis_server/test/client/completion_driver_test.dart b/pkg/analysis_server/test/client/completion_driver_test.dart index 50a60218be0..732e5bb6753 100644 --- a/pkg/analysis_server/test/client/completion_driver_test.dart +++ b/pkg/analysis_server/test/client/completion_driver_test.dart @@ -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 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 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 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 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 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 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 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.) } diff --git a/pkg/analysis_server/test/client/impl/completion_driver.dart b/pkg/analysis_server/test/client/impl/completion_driver.dart index 09285b79956..66720b923f1 100644 --- a/pkg/analysis_server/test/client/impl/completion_driver.dart +++ b/pkg/analysis_server/test/client/impl/completion_driver.dart @@ -130,6 +130,20 @@ class CompletionDriver extends AbstractClient with ExpectMixin { return suggestions; } + Future> 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); diff --git a/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart b/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart index 3b95fd51135..477d52b2e2d 100644 --- a/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart +++ b/pkg/analysis_server/test/src/domains/completion/available_suggestion_sets_test.dart @@ -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)}, diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart index 8e8b939013d..e373a74b8d5 100644 --- a/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart +++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart @@ -66,6 +66,9 @@ abstract class Completer { } abstract class Timer { + factory Timer(Duration duration, void Function() callback) { + throw 0; + } static void run(void callback()) {} } ''',