@@ -266,8 +266,8 @@ class CodeCompletionCallbacksImpl : public IDEInspectionCallbacks {
266266
267267 void completeTypeDeclResultBeginning () override ;
268268 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 ;
271271
272272 void completeCaseStmtKeyword () override ;
273273 void completeCaseStmtBeginning (CodeCompletionExpr *E) override ;
@@ -494,21 +494,16 @@ void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(
494494 CurDeclContext = P.CurDeclContext ;
495495}
496496
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;
504500 ParsedTypeLoc = TypeLoc (TR);
505501 CurDeclContext = P.CurDeclContext ;
506502}
507503
508- void CodeCompletionCallbacksImpl::completeTypeIdentifierWithoutDot (
509- DeclRefTypeRepr *TR) {
504+ void CodeCompletionCallbacksImpl::completeTypeSimpleWithoutDot (TypeRepr *TR) {
510505 assert (TR);
511- Kind = CompletionKind::TypeIdentifierWithoutDot ;
506+ Kind = CompletionKind::TypeSimpleWithoutDot ;
512507 ParsedTypeLoc = TypeLoc (TR);
513508 CurDeclContext = P.CurDeclContext ;
514509}
@@ -953,6 +948,13 @@ addClosureSignatureKeywordsIfApplicable(CodeCompletionResultSink &Sink,
953948
954949void CodeCompletionCallbacksImpl::addKeywords (CodeCompletionResultSink &Sink,
955950 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+
956958 switch (Kind) {
957959 case CompletionKind::None:
958960 case CompletionKind::DotExpr:
@@ -974,13 +976,9 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
974976 case CompletionKind::OptionalBinding:
975977 break ;
976978
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 ();
982981 break ;
983- }
984982
985983 case CompletionKind::AccessorBeginning: {
986984 // TODO: Omit already declared or mutally exclusive accessors.
@@ -1037,8 +1035,15 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
10371035
10381036 break ;
10391037 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+ }
10421047 break ;
10431048
10441049 case CompletionKind::TypeDeclResultBeginning: {
@@ -1241,8 +1246,8 @@ void swift::ide::postProcessCompletionResults(
12411246 if (result->getKind () == CodeCompletionResultKind::Declaration &&
12421247 result->getAssociatedDeclKind () == CodeCompletionDeclKind::Protocol &&
12431248 Kind != CompletionKind::TypeSimpleBeginning &&
1244- Kind != CompletionKind::TypeIdentifierWithoutDot &&
1245- Kind != CompletionKind::TypeIdentifierWithDot &&
1249+ Kind != CompletionKind::TypeSimpleWithoutDot &&
1250+ Kind != CompletionKind::TypeSimpleWithDot &&
12461251 Kind != CompletionKind::TypeDeclResultBeginning &&
12471252 Kind != CompletionKind::GenericRequirement) {
12481253 flair |= CodeCompletionFlairBit::RareTypeAtCurrentPosition;
@@ -1597,7 +1602,7 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
15971602 return ;
15981603
15991604 undoSingleExpressionReturn (CurDeclContext);
1600- if (Kind != CompletionKind::TypeIdentifierWithDot ) {
1605+ if (Kind != CompletionKind::TypeSimpleWithDot ) {
16011606 // Type member completion does not need a type-checked AST.
16021607 typeCheckContextAt (
16031608 TypeCheckASTNodeAtLocContext::declContext (CurDeclContext),
@@ -1753,13 +1758,13 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
17531758 break ;
17541759 }
17551760
1756- case CompletionKind::TypeIdentifierWithDot : {
1761+ case CompletionKind::TypeSimpleWithDot : {
17571762 Lookup.setHaveDot (SourceLoc ());
17581763 Lookup.getTypeCompletions (ParsedTypeLoc.getType ());
17591764 break ;
17601765 }
17611766
1762- case CompletionKind::TypeIdentifierWithoutDot : {
1767+ case CompletionKind::TypeSimpleWithoutDot : {
17631768 Lookup.getTypeCompletions (ParsedTypeLoc.getType ());
17641769 break ;
17651770 }
0 commit comments