@@ -266,8 +266,8 @@ class CodeCompletionCallbacksImpl : public IDEInspectionCallbacks {
266
266
267
267
void completeTypeDeclResultBeginning () override ;
268
268
void completeTypeSimpleBeginning () override ;
269
- void completeTypeIdentifierWithDot (DeclRefTypeRepr *TR) override ;
270
- void completeTypeIdentifierWithoutDot (DeclRefTypeRepr *TR) override ;
269
+ void completeTypeSimpleWithDot (TypeRepr *TR) override ;
270
+ void completeTypeSimpleWithoutDot (TypeRepr *TR) override ;
271
271
272
272
void completeCaseStmtKeyword () override ;
273
273
void completeCaseStmtBeginning (CodeCompletionExpr *E) override ;
@@ -494,21 +494,16 @@ void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(
494
494
CurDeclContext = P.CurDeclContext ;
495
495
}
496
496
497
- void CodeCompletionCallbacksImpl::completeTypeIdentifierWithDot (
498
- DeclRefTypeRepr *TR) {
499
- if (!TR) {
500
- completeTypeSimpleBeginning ();
501
- return ;
502
- }
503
- Kind = CompletionKind::TypeIdentifierWithDot;
497
+ void CodeCompletionCallbacksImpl::completeTypeSimpleWithDot (TypeRepr *TR) {
498
+ assert (TR);
499
+ Kind = CompletionKind::TypeSimpleWithDot;
504
500
ParsedTypeLoc = TypeLoc (TR);
505
501
CurDeclContext = P.CurDeclContext ;
506
502
}
507
503
508
- void CodeCompletionCallbacksImpl::completeTypeIdentifierWithoutDot (
509
- DeclRefTypeRepr *TR) {
504
+ void CodeCompletionCallbacksImpl::completeTypeSimpleWithoutDot (TypeRepr *TR) {
510
505
assert (TR);
511
- Kind = CompletionKind::TypeIdentifierWithoutDot ;
506
+ Kind = CompletionKind::TypeSimpleWithoutDot ;
512
507
ParsedTypeLoc = TypeLoc (TR);
513
508
CurDeclContext = P.CurDeclContext ;
514
509
}
@@ -953,6 +948,13 @@ addClosureSignatureKeywordsIfApplicable(CodeCompletionResultSink &Sink,
953
948
954
949
void CodeCompletionCallbacksImpl::addKeywords (CodeCompletionResultSink &Sink,
955
950
bool MaybeFuncBody) {
951
+ auto addEffectsSpecifierKeywords = [&] {
952
+ if (!llvm::is_contained (ParsedKeywords, " async" ))
953
+ addKeyword (Sink, " async" , CodeCompletionKeywordKind::None);
954
+ if (!llvm::is_contained (ParsedKeywords, " throws" ))
955
+ addKeyword (Sink, " throws" , CodeCompletionKeywordKind::kw_throws);
956
+ };
957
+
956
958
switch (Kind) {
957
959
case CompletionKind::None:
958
960
case CompletionKind::DotExpr:
@@ -974,13 +976,9 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
974
976
case CompletionKind::OptionalBinding:
975
977
break ;
976
978
977
- case CompletionKind::EffectsSpecifier: {
978
- if (!llvm::is_contained (ParsedKeywords, " async" ))
979
- addKeyword (Sink, " async" , CodeCompletionKeywordKind::None);
980
- if (!llvm::is_contained (ParsedKeywords, " throws" ))
981
- addKeyword (Sink, " throws" , CodeCompletionKeywordKind::kw_throws);
979
+ case CompletionKind::EffectsSpecifier:
980
+ addEffectsSpecifierKeywords ();
982
981
break ;
983
- }
984
982
985
983
case CompletionKind::AccessorBeginning: {
986
984
// TODO: Omit already declared or mutally exclusive accessors.
@@ -1037,8 +1035,15 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
1037
1035
1038
1036
break ;
1039
1037
case CompletionKind::CaseStmtBeginning:
1040
- case CompletionKind::TypeIdentifierWithDot:
1041
- case CompletionKind::TypeIdentifierWithoutDot:
1038
+ case CompletionKind::TypeSimpleWithDot:
1039
+ break ;
1040
+
1041
+ case CompletionKind::TypeSimpleWithoutDot:
1042
+ // Suggest effects specifiers after a tuple type because it may be
1043
+ // intended as a parameter list.
1044
+ if (isa_and_nonnull<TupleTypeRepr>(ParsedTypeLoc.getTypeRepr ())) {
1045
+ addEffectsSpecifierKeywords ();
1046
+ }
1042
1047
break ;
1043
1048
1044
1049
case CompletionKind::TypeDeclResultBeginning: {
@@ -1241,8 +1246,8 @@ void swift::ide::postProcessCompletionResults(
1241
1246
if (result->getKind () == CodeCompletionResultKind::Declaration &&
1242
1247
result->getAssociatedDeclKind () == CodeCompletionDeclKind::Protocol &&
1243
1248
Kind != CompletionKind::TypeSimpleBeginning &&
1244
- Kind != CompletionKind::TypeIdentifierWithoutDot &&
1245
- Kind != CompletionKind::TypeIdentifierWithDot &&
1249
+ Kind != CompletionKind::TypeSimpleWithoutDot &&
1250
+ Kind != CompletionKind::TypeSimpleWithDot &&
1246
1251
Kind != CompletionKind::TypeDeclResultBeginning &&
1247
1252
Kind != CompletionKind::GenericRequirement) {
1248
1253
flair |= CodeCompletionFlairBit::RareTypeAtCurrentPosition;
@@ -1597,7 +1602,7 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
1597
1602
return ;
1598
1603
1599
1604
undoSingleExpressionReturn (CurDeclContext);
1600
- if (Kind != CompletionKind::TypeIdentifierWithDot ) {
1605
+ if (Kind != CompletionKind::TypeSimpleWithDot ) {
1601
1606
// Type member completion does not need a type-checked AST.
1602
1607
typeCheckContextAt (
1603
1608
TypeCheckASTNodeAtLocContext::declContext (CurDeclContext),
@@ -1753,13 +1758,13 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
1753
1758
break ;
1754
1759
}
1755
1760
1756
- case CompletionKind::TypeIdentifierWithDot : {
1761
+ case CompletionKind::TypeSimpleWithDot : {
1757
1762
Lookup.setHaveDot (SourceLoc ());
1758
1763
Lookup.getTypeCompletions (ParsedTypeLoc.getType ());
1759
1764
break ;
1760
1765
}
1761
1766
1762
- case CompletionKind::TypeIdentifierWithoutDot : {
1767
+ case CompletionKind::TypeSimpleWithoutDot : {
1763
1768
Lookup.getTypeCompletions (ParsedTypeLoc.getType ());
1764
1769
break ;
1765
1770
}
0 commit comments