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 e92436b20177..1b62c5160dea 100644 --- a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart +++ b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart @@ -191,6 +191,12 @@ protocol.AvailableSuggestion _protocolAvailableSuggestion( } } else if (declaration.kind == DeclarationKind.ENUM_CONSTANT) { label = '${declaration.parent.name}.${declaration.name}'; + } else if (declaration.kind == DeclarationKind.GETTER && + declaration.isStatic) { + label = '${declaration.parent.name}.${declaration.name}'; + } else if (declaration.kind == DeclarationKind.FIELD && + declaration.isStatic) { + label = '${declaration.parent.name}.${declaration.name}'; } else { return null; } diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart index 72a80a4ca180..15ee75e28367 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart @@ -240,7 +240,10 @@ class DartCompletionManager implements CompletionContributor { kinds.add(protocol.ElementKind.CONSTRUCTOR); kinds.add(protocol.ElementKind.ENUM_CONSTANT); kinds.add(protocol.ElementKind.EXTENSION); + // Static fields. + kinds.add(protocol.ElementKind.FIELD); kinds.add(protocol.ElementKind.FUNCTION); + // Static and top-level properties. kinds.add(protocol.ElementKind.GETTER); kinds.add(protocol.ElementKind.SETTER); kinds.add(protocol.ElementKind.TOP_LEVEL_VARIABLE); diff --git a/pkg/analysis_server/test/client/completion_driver_test.dart b/pkg/analysis_server/test/client/completion_driver_test.dart index 4d30ab6934eb..0e41a7de6833 100644 --- a/pkg/analysis_server/test/client/completion_driver_test.dart +++ b/pkg/analysis_server/test/client/completion_driver_test.dart @@ -385,6 +385,41 @@ void main() { kind: CompletionSuggestionKind.INVOCATION); } + Future test_project_lib_fields_class() async { + await addProjectFile('lib/a.dart', r''' +class A { + int f = 0; +} +'''); + + await addTestFile(''' +void main() { + ^ +} +'''); + + assertNoSuggestion(completion: 'f'); + } + + Future test_project_lib_fields_static() async { + await addProjectFile('lib/a.dart', r''' +class A { + static int f = 0; +} +'''); + + await addTestFile(''' +void main() { + ^ +} +'''); + + assertSuggestion( + completion: 'A.f', + element: ElementKind.FIELD, + kind: CompletionSuggestionKind.INVOCATION); + } + Future test_project_lib_getters_class() async { await addProjectFile('lib/a.dart', r''' class A { @@ -401,7 +436,6 @@ void main() { assertNoSuggestion(completion: 'g'); } - @failingTest Future test_project_lib_getters_static() async { await addProjectFile('lib/a.dart', r''' class A { @@ -415,7 +449,10 @@ void main() { } '''); - assertSuggestion(completion: 'g'); + assertSuggestion( + completion: 'A.g', + element: ElementKind.GETTER, + kind: CompletionSuggestionKind.INVOCATION); } /// See: https://github.com/dart-lang/sdk/issues/40626 @@ -488,7 +525,7 @@ void main() { } '''); - assertNoSuggestion(completion: 'g'); + assertNoSuggestion(completion: 'A.g'); } /// See: https://github.com/dart-lang/sdk/issues/40626 diff --git a/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart b/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart index f35030f7bd6c..e065bb78ac88 100644 --- a/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart +++ b/pkg/analysis_server/test/src/domains/completion/get_suggestions_available_test.dart @@ -182,6 +182,7 @@ main() { ElementKind.ENUM, ElementKind.ENUM_CONSTANT, ElementKind.EXTENSION, + ElementKind.FIELD, ElementKind.FUNCTION, ElementKind.FUNCTION_TYPE_ALIAS, ElementKind.GETTER,