Skip to content

Commit 6fe971b

Browse files
author
Dart CI
committed
Version 3.10.0-75.0.dev
Merge c5eba84 into dev
2 parents 5b44a0f + c5eba84 commit 6fe971b

File tree

21 files changed

+480
-63
lines changed

21 files changed

+480
-63
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class DeclarationHelper {
8888
/// possible.
8989
final bool preferNonInvocation;
9090

91+
/// Whether suggestions are for completing a dot shorthand.
92+
final bool suggestingDotShorthand;
93+
9194
/// Whether unnamed constructors should be suggested as `.new`.
9295
final bool suggestUnnamedAsNew;
9396

@@ -135,6 +138,7 @@ class DeclarationHelper {
135138
required this.excludeTypeNames,
136139
required this.objectPatternAllowed,
137140
required this.preferNonInvocation,
141+
required this.suggestingDotShorthand,
138142
required this.suggestUnnamedAsNew,
139143
required this.skipImports,
140144
required this.excludedNodes,
@@ -1504,7 +1508,8 @@ class DeclarationHelper {
15041508
}
15051509
if (!mustBeAssignable) {
15061510
var allowNonFactory =
1507-
containingElement is ClassElement && !containingElement.isAbstract;
1511+
containingElement is ClassElement && !containingElement.isAbstract ||
1512+
containingElement is ExtensionTypeElement;
15081513
for (var constructor in constructors) {
15091514
if (constructor.isVisibleIn(request.libraryElement) &&
15101515
(allowNonFactory || constructor.isFactory)) {
@@ -1826,8 +1831,15 @@ class DeclarationHelper {
18261831
);
18271832
}
18281833

1834+
// Use the constructor element's name without the interface type to
1835+
// calculate the matcher score for dot shorthands.
1836+
var elementName = element.name;
1837+
var matcherName =
1838+
suggestingDotShorthand && elementName != null
1839+
? elementName
1840+
: element.displayName;
18291841
// TODO(keertip): Compute the completion string.
1830-
var matcherScore = state.matcher.score(element.displayName);
1842+
var matcherScore = state.matcher.score(matcherName);
18311843
if (matcherScore != -1) {
18321844
var isTearOff =
18331845
preferNonInvocation || (mustBeConstant && !element.isConst);

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
172172
bool excludeTypeNames = false,
173173
bool objectPatternAllowed = false,
174174
bool preferNonInvocation = false,
175+
bool suggestingDotShorthand = false,
175176
bool suggestUnnamedAsNew = false,
176177
Set<AstNode> excludedNodes = const {},
177178
}) {
@@ -199,7 +200,8 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
199200
helper.mustBeStatic == mustBeStatic &&
200201
helper.mustBeType == mustBeType &&
201202
helper.preferNonInvocation == preferNonInvocation &&
202-
helper.objectPatternAllowed == objectPatternAllowed);
203+
helper.objectPatternAllowed == objectPatternAllowed &&
204+
helper.suggestingDotShorthand == suggestingDotShorthand);
203205
}());
204206
return _declarationHelper ??= DeclarationHelper(
205207
request: state.request,
@@ -217,6 +219,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
217219
excludeTypeNames: excludeTypeNames,
218220
objectPatternAllowed: objectPatternAllowed,
219221
preferNonInvocation: preferNonInvocation,
222+
suggestingDotShorthand: suggestingDotShorthand,
220223
suggestUnnamedAsNew: suggestUnnamedAsNew,
221224
skipImports: skipImports,
222225
excludedNodes: excludedNodes,
@@ -923,6 +926,23 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
923926
}
924927
}
925928

929+
@override
930+
void visitDotShorthandInvocation(DotShorthandInvocation node) {
931+
var period = node.period;
932+
if (offset >= period.end && offset <= node.memberName.end) {
933+
var contextType = _computeContextType(node);
934+
if (contextType == null) return;
935+
936+
var element = contextType.element;
937+
if (element == null) return;
938+
939+
declarationHelper(
940+
suggestingDotShorthand: true,
941+
suggestUnnamedAsNew: true,
942+
).addStaticMembersOfElement(element);
943+
}
944+
}
945+
926946
@override
927947
void visitDotShorthandPropertyAccess(DotShorthandPropertyAccess node) {
928948
var contextType = _computeContextType(node);
@@ -931,16 +951,16 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
931951
var element = contextType.element;
932952
if (element == null) return;
933953

934-
var parent = node.parent;
935-
var mustBeAssignable =
936-
parent is AssignmentExpression && node == parent.leftHandSide;
937-
var helper = declarationHelper(
938-
mustBeAssignable: mustBeAssignable,
954+
// Add all getters, methods, and constructors.
955+
// When the user needs completing with a `.` or a `.prefix`, the suggestions
956+
// can be any of the three.
957+
declarationHelper(
958+
suggestingDotShorthand: true,
939959
preferNonInvocation:
940960
element is InterfaceElement &&
941961
state.request.shouldSuggestTearOff(element),
942-
);
943-
helper.addStaticMembersOfElement(element);
962+
suggestUnnamedAsNew: true,
963+
).addStaticMembersOfElement(element);
944964
}
945965

946966
@override

pkg/analysis_server/test/abstract_context.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class AbstractContextTest
5858

5959
List<String> get collectionIncludedPaths => [workspaceRootPath];
6060

61+
/// The line terminator being used for test files and to be expected in edits.
62+
String get eol => testEol;
63+
6164
/// Return a list of the experiments that are to be enabled for tests in this
6265
/// class, an empty list if there are no experiments that should be enabled.
6366
List<String> get experiments => experimentsForTests;

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@ class ConstructorInvocationTest extends AbstractCompletionDriverTest
1717
with ConstructorInvocationTestCases {}
1818

1919
mixin ConstructorInvocationTestCases on AbstractCompletionDriverTest {
20+
Future<void> test_extensionType() async {
21+
allowedIdentifiers = {'named'};
22+
await computeSuggestions('''
23+
extension type C(int x) {
24+
C.named(this.x);
25+
}
26+
void f() {
27+
C c = C.^
28+
}
29+
''');
30+
assertResponse(r'''
31+
suggestions
32+
named
33+
kind: constructorInvocation
34+
''');
35+
}
36+
37+
Future<void> test_extensionType_withPrefix() async {
38+
allowedIdentifiers = {'named'};
39+
await computeSuggestions('''
40+
extension type C(int x) {
41+
C.named(this.x);
42+
}
43+
void f() {
44+
C c = C.n^
45+
}
46+
''');
47+
assertResponse(r'''
48+
replacement
49+
left: 1
50+
suggestions
51+
named
52+
kind: constructorInvocation
53+
''');
54+
}
55+
2056
Future<void> test_it() async {
2157
await computeSuggestions('''
2258
class C {

0 commit comments

Comments
 (0)