Skip to content

Commit 42394e5

Browse files
FMorschelCommit Queue
authored and
Commit Queue
committed
[DAS] Better docs auto-complete with extensions and typedefs
Fixes: #60423 Change-Id: I0907a52a0c7787adc3de21c82bb60aced8263d2d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419422 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 478d1ef commit 42394e5

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,10 @@ class DeclarationHelper {
17421742
importData: importData,
17431743
element: element,
17441744
matcherScore: matcherScore,
1745+
kind:
1746+
preferNonInvocation
1747+
? CompletionSuggestionKind.IDENTIFIER
1748+
: CompletionSuggestionKind.INVOCATION,
17451749
);
17461750
collector.addSuggestion(suggestion);
17471751
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2265,8 +2265,9 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
22652265
var helper = declarationHelper(
22662266
mustBeAssignable: mustBeAssignable,
22672267
preferNonInvocation:
2268-
element is InterfaceElement2 &&
2269-
state.request.shouldSuggestTearOff(element),
2268+
node.parent is CommentReference ||
2269+
(element is InterfaceElement2 &&
2270+
state.request.shouldSuggestTearOff(element)),
22702271
);
22712272
if (node.parent is CommentReference) {
22722273
if (element is InterfaceElement2) {

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

+32-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MyClass1 {
4040
assertResponse(r'''
4141
suggestions
4242
constructor1
43-
kind: constructorInvocation
43+
kind: constructor
4444
''');
4545
}
4646

@@ -87,7 +87,22 @@ replacement
8787
left: 3
8888
suggestions
8989
MyExt
90-
kind: extensionInvocation
90+
kind: extension
91+
''');
92+
}
93+
94+
Future<void> test_extension2() async {
95+
allowedIdentifiers = const {'isEven'};
96+
await computeSuggestions('''
97+
/// This doc should suggest other things like [int.isE^].
98+
extension MyExt on int {}
99+
''');
100+
assertResponse(r'''
101+
replacement
102+
left: 3
103+
suggestions
104+
isEven
105+
kind: getter
91106
''');
92107
}
93108

@@ -368,6 +383,21 @@ suggestions
368383
''');
369384
}
370385

386+
Future<void> test_typedef2() async {
387+
allowedIdentifiers = const {'delayed'};
388+
await computeSuggestions('''
389+
/// This doc should suggest other things like [Future.de^].
390+
typedef MyTypedef = int Function();
391+
''');
392+
assertResponse(r'''
393+
replacement
394+
left: 2
395+
suggestions
396+
delayed
397+
kind: constructor
398+
''');
399+
}
400+
371401
Future<void> test_typeParameter() async {
372402
allowedIdentifiers = const {'TypeParam'};
373403
await computeSuggestions('''

pkg/analyzer/lib/src/dart/ast/ast.dart

+11-13
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ sealed class AnnotatedNodeImpl extends AstNodeImpl with _AnnotatedNodeMixin {
160160
return metadataToken;
161161
}
162162

163-
@override
164-
ChildEntities get _childEntities {
165-
return ChildEntities()
166-
..addNode('documentationComment', documentationComment)
167-
..addNodeList('metadata', metadata);
168-
}
169-
170163
@override
171164
void visitChildren(AstVisitor visitor) {
172165
_visitCommentAndAnnotations(visitor);
@@ -6737,7 +6730,7 @@ final class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
67376730
}
67386731

67396732
@override
6740-
ChildEntities get _childEntities => ChildEntities()
6733+
ChildEntities get _childEntities => super._childEntities
67416734
..addToken('augmentKeyword', augmentKeyword)
67426735
..addToken('extensionKeyword', extensionKeyword)
67436736
..addToken('name', name)
@@ -9452,8 +9445,7 @@ final class GenericTypeAliasImpl extends TypeAliasImpl
94529445
}
94539446

94549447
@override
9455-
ChildEntities get _childEntities => ChildEntities()
9456-
..addNodeList('metadata', metadata)
9448+
ChildEntities get _childEntities => super._childEntities
94579449
..addToken('augmentKeyword', augmentKeyword)
94589450
..addToken('typedefKeyword', typedefKeyword)
94599451
..addToken('name', name)
@@ -13327,9 +13319,7 @@ sealed class NormalFormalParameterImpl extends FormalParameterImpl
1332713319

1332813320
@override
1332913321
ChildEntities get _childEntities {
13330-
return ChildEntities()
13331-
..addNode('documentationComment', documentationComment)
13332-
..addNodeList('metadata', metadata)
13322+
return super._childEntities
1333313323
..addToken('requiredKeyword', requiredKeyword)
1333413324
..addToken('covariantKeyword', covariantKeyword);
1333513325
}
@@ -19446,6 +19436,14 @@ base mixin _AnnotatedNodeMixin on AstNodeImpl implements AnnotatedNode {
1944619436
]..sort(AstNode.LEXICAL_ORDER);
1944719437
}
1944819438

19439+
@override
19440+
@mustCallSuper
19441+
ChildEntities get _childEntities {
19442+
return ChildEntities()
19443+
..addNode('documentationComment', documentationComment)
19444+
..addNodeList('metadata', metadata);
19445+
}
19446+
1944919447
/// Returns `true` if there are no annotations before the comment.
1945019448
///
1945119449
/// Note that a result of `true` doesn't imply that there's a comment, nor

0 commit comments

Comments
 (0)