Skip to content

Commit

Permalink
add static fields and getters to available suggestions
Browse files Browse the repository at this point in the history
Fixes: #40699

Change-Id: Id60307de949395c2274cb35ac4d14521b301437d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136525
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and commit-bot@chromium.org committed Feb 20, 2020
1 parent 612728f commit 6da0090
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 40 additions & 3 deletions pkg/analysis_server/test/client/completion_driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,41 @@ void main() {
kind: CompletionSuggestionKind.INVOCATION);
}

Future<void> 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<void> 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<void> test_project_lib_getters_class() async {
await addProjectFile('lib/a.dart', r'''
class A {
Expand All @@ -401,7 +436,6 @@ void main() {
assertNoSuggestion(completion: 'g');
}

@failingTest
Future<void> test_project_lib_getters_static() async {
await addProjectFile('lib/a.dart', r'''
class A {
Expand All @@ -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
Expand Down Expand Up @@ -488,7 +525,7 @@ void main() {
}
''');

assertNoSuggestion(completion: 'g');
assertNoSuggestion(completion: 'A.g');
}

/// See: https://github.com/dart-lang/sdk/issues/40626
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ main() {
ElementKind.ENUM,
ElementKind.ENUM_CONSTANT,
ElementKind.EXTENSION,
ElementKind.FIELD,
ElementKind.FUNCTION,
ElementKind.FUNCTION_TYPE_ALIAS,
ElementKind.GETTER,
Expand Down

0 comments on commit 6da0090

Please sign in to comment.