Skip to content

Commit a0db69f

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Considers factory keyword on constructors auto-complete
[email protected] Fixes #59896 Change-Id: I47c51bc521f97398ae19a8d124e836baadfdabd4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405200 Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent da9de5a commit a0db69f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,9 +4024,10 @@ extension on AstNode {
40244024
while (enclosingMember != null) {
40254025
if (enclosingMember is MethodDeclaration) {
40264026
return enclosingMember.isStatic;
4027-
} else if (enclosingMember is FunctionBody &&
4028-
enclosingMember.parent is ConstructorDeclaration) {
4029-
return false;
4027+
} else if (enclosingMember.parent case ConstructorDeclaration(
4028+
:var factoryKeyword,
4029+
) when enclosingMember is FunctionBody) {
4030+
return factoryKeyword != null;
40304031
} else if (enclosingMember is VariableDeclarationList &&
40314032
enclosingMember.parent is FieldDeclaration) {
40324033
return !enclosingMember.isLate;

pkg/analysis_server/test/services/completion/dart/location/constructor_declaration_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class ConstructorDeclarationTest extends AbstractCompletionDriverTest
1717
with ConstructorDeclarationTestCases {}
1818

1919
mixin ConstructorDeclarationTestCases on AbstractCompletionDriverTest {
20+
Future<void> test_factory_noInstanceValues() async {
21+
await computeSuggestions('''
22+
class A {
23+
A();
24+
factory A.n() {
25+
^
26+
return A();
27+
}
28+
bool isEmpty = false;
29+
}
30+
''');
31+
assertNoSuggestion(completion: 'isEmpty');
32+
}
33+
2034
Future<void> test_factory_redirectedConstructor_afterName() async {
2135
await computeSuggestions('''
2236
class A {

0 commit comments

Comments
 (0)