@@ -3208,9 +3208,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
3208
3208
3209
3209
// Parse a 'where' clause if present, adding it to our GenericParamList.
3210
3210
if (Tok.is (tok::kw_where)) {
3211
- auto whereStatus = parseFreestandingGenericWhereClause (genericParams);
3212
- if (whereStatus.shouldStopParsing ())
3213
- return whereStatus;
3211
+ Status |= parseFreestandingGenericWhereClause (genericParams);
3214
3212
}
3215
3213
3216
3214
if (UnderlyingTy.isNull ()) {
@@ -3224,6 +3222,9 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
3224
3222
TAD->getUnderlyingTypeLoc () = UnderlyingTy.getPtrOrNull ();
3225
3223
TAD->getAttrs () = Attributes;
3226
3224
3225
+ if (Status.hasCodeCompletion () && CodeCompletion)
3226
+ CodeCompletion->setParsedDecl (TAD);
3227
+
3227
3228
// Exit the scope introduced for the generic parameters.
3228
3229
GenericsScope.reset ();
3229
3230
@@ -4771,7 +4772,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4771
4772
Optional<Scope> GenericsScope;
4772
4773
GenericsScope.emplace (this , ScopeKind::Generics);
4773
4774
GenericParamList *GenericParams;
4774
- bool GPHasCodeCompletion = false ;
4775
+ bool SignatureHasCodeCompletion = false ;
4775
4776
// If the name is an operator token that ends in '<' and the following token
4776
4777
// is an identifier, split the '<' off as a separate token. This allows things
4777
4778
// like 'func ==<T>(x:T, y:T) {}' to parse as '==' with generic type variable
@@ -4783,7 +4784,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4783
4784
SourceLoc LAngleLoc = NameLoc.getAdvancedLoc (SimpleName.str ().size ());
4784
4785
auto Result = parseGenericParameters (LAngleLoc);
4785
4786
GenericParams = Result.getPtrOrNull ();
4786
- GPHasCodeCompletion |= Result.hasCodeCompletion ();
4787
+ SignatureHasCodeCompletion |= Result.hasCodeCompletion ();
4787
4788
4788
4789
auto NameTokText = NameTok.getRawText ();
4789
4790
markSplitToken (tok::identifier,
@@ -4794,9 +4795,9 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4794
4795
} else {
4795
4796
auto Result = maybeParseGenericParams ();
4796
4797
GenericParams = Result.getPtrOrNull ();
4797
- GPHasCodeCompletion |= Result.hasCodeCompletion ();
4798
+ SignatureHasCodeCompletion |= Result.hasCodeCompletion ();
4798
4799
}
4799
- if (GPHasCodeCompletion && !CodeCompletion)
4800
+ if (SignatureHasCodeCompletion && !CodeCompletion)
4800
4801
return makeParserCodeCompletionStatus ();
4801
4802
4802
4803
SmallVector<ParameterList*, 8 > BodyParams;
@@ -4820,6 +4821,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4820
4821
parseFunctionSignature (SimpleName, FullName, BodyParams, DefaultArgs,
4821
4822
throwsLoc, rethrows, FuncRetTy);
4822
4823
4824
+ SignatureHasCodeCompletion |= SignatureStatus.hasCodeCompletion ();
4823
4825
if (SignatureStatus.hasCodeCompletion () && !CodeCompletion) {
4824
4826
// Trigger delayed parsing, no need to continue.
4825
4827
return SignatureStatus;
@@ -4830,8 +4832,11 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4830
4832
// Parse a 'where' clause if present, adding it to our GenericParamList.
4831
4833
if (Tok.is (tok::kw_where)) {
4832
4834
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
4833
- if (whereStatus.shouldStopParsing ())
4835
+ SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
4836
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
4837
+ // Trigger delayed parsing, no need to continue.
4834
4838
return whereStatus;
4839
+ }
4835
4840
}
4836
4841
4837
4842
// Protocol method arguments may not have default values.
@@ -4866,13 +4871,9 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4866
4871
// they are available.
4867
4872
FD->getAttrs () = Attributes;
4868
4873
4869
- // Code completion for the generic type params.
4870
- if (GPHasCodeCompletion)
4871
- CodeCompletion->setDelayedParsedDecl (FD);
4872
-
4873
4874
// Pass the function signature to code completion.
4874
- if (SignatureStatus. hasCodeCompletion () )
4875
- CodeCompletion->setDelayedParsedDecl (FD);
4875
+ if (SignatureHasCodeCompletion )
4876
+ CodeCompletion->setParsedDecl (FD);
4876
4877
4877
4878
DefaultArgs.setFunctionContext (FD);
4878
4879
for (auto PL : FD->getParameterLists ())
@@ -5015,11 +5016,17 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
5015
5016
// Parse a 'where' clause if present, adding it to our GenericParamList.
5016
5017
if (Tok.is (tok::kw_where)) {
5017
5018
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5018
- if (whereStatus.shouldStopParsing ())
5019
+ Status |= whereStatus;
5020
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5021
+ // Trigger delayed parsing, no need to continue.
5019
5022
return whereStatus;
5023
+ }
5020
5024
ED->setGenericParams (GenericParams);
5021
5025
}
5022
5026
5027
+ if (Status.hasCodeCompletion () && CodeCompletion)
5028
+ CodeCompletion->setParsedDecl (ED);
5029
+
5023
5030
SourceLoc LBLoc, RBLoc;
5024
5031
if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_enum)) {
5025
5032
LBLoc = PreviousLoc;
@@ -5272,11 +5279,16 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
5272
5279
// Parse a 'where' clause if present, adding it to our GenericParamList.
5273
5280
if (Tok.is (tok::kw_where)) {
5274
5281
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5275
- if (whereStatus.shouldStopParsing ())
5282
+ Status |= whereStatus;
5283
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5284
+ // Trigger delayed parsing, no need to continue.
5276
5285
return whereStatus;
5286
+ }
5277
5287
SD->setGenericParams (GenericParams);
5278
5288
}
5279
5289
5290
+ if (Status.hasCodeCompletion () && CodeCompletion)
5291
+ CodeCompletion->setParsedDecl (SD);
5280
5292
5281
5293
SourceLoc LBLoc, RBLoc;
5282
5294
if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
@@ -5355,11 +5367,17 @@ ParserResult<ClassDecl> Parser::parseDeclClass(SourceLoc ClassLoc,
5355
5367
// Parse a 'where' clause if present, adding it to our GenericParamList.
5356
5368
if (Tok.is (tok::kw_where)) {
5357
5369
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5358
- if (whereStatus.shouldStopParsing ())
5370
+ Status |= whereStatus;
5371
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5372
+ // Trigger delayed parsing, no need to continue.
5359
5373
return whereStatus;
5374
+ }
5360
5375
CD->setGenericParams (GenericParams);
5361
5376
}
5362
5377
5378
+ if (Status.hasCodeCompletion () && CodeCompletion)
5379
+ CodeCompletion->setParsedDecl (CD);
5380
+
5363
5381
SourceLoc LBLoc, RBLoc;
5364
5382
if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_class)) {
5365
5383
LBLoc = PreviousLoc;
@@ -5502,13 +5520,13 @@ Parser::parseDeclSubscript(ParseDeclOptions Flags,
5502
5520
Optional<Scope> GenericsScope;
5503
5521
GenericsScope.emplace (this , ScopeKind::Generics);
5504
5522
GenericParamList *GenericParams;
5505
- bool GPHasCodeCompletion = false ;
5523
+ bool SignatureHasCodeCompletion = false ;
5506
5524
5507
5525
auto Result = maybeParseGenericParams ();
5508
5526
GenericParams = Result.getPtrOrNull ();
5509
- GPHasCodeCompletion |= Result.hasCodeCompletion ();
5527
+ SignatureHasCodeCompletion |= Result.hasCodeCompletion ();
5510
5528
5511
- if (GPHasCodeCompletion && !CodeCompletion)
5529
+ if (SignatureHasCodeCompletion && !CodeCompletion)
5512
5530
return makeParserCodeCompletionStatus ();
5513
5531
5514
5532
// Parse the parameter list.
@@ -5537,8 +5555,11 @@ Parser::parseDeclSubscript(ParseDeclOptions Flags,
5537
5555
// Parse a 'where' clause if present, adding it to our GenericParamList.
5538
5556
if (Tok.is (tok::kw_where)) {
5539
5557
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5540
- if (whereStatus.shouldStopParsing ())
5558
+ SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
5559
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5560
+ // Trigger delayed parsing, no need to continue.
5541
5561
return whereStatus;
5562
+ }
5542
5563
}
5543
5564
5544
5565
// Build an AST for the subscript declaration.
@@ -5551,11 +5572,9 @@ Parser::parseDeclSubscript(ParseDeclOptions Flags,
5551
5572
GenericParams);
5552
5573
Subscript->getAttrs () = Attributes;
5553
5574
5554
- // Code completion for the generic type params.
5555
- //
5556
- // FIXME: What is this?
5557
- if (GPHasCodeCompletion)
5558
- CodeCompletion->setDelayedParsedDecl (Subscript);
5575
+ // Pass the function signature to code completion.
5576
+ if (SignatureHasCodeCompletion)
5577
+ CodeCompletion->setParsedDecl (Subscript);
5559
5578
5560
5579
Decls.push_back (Subscript);
5561
5580
@@ -5633,10 +5652,12 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
5633
5652
// Parse the parameters.
5634
5653
DefaultArgumentInfo DefaultArgs (/* inTypeContext*/ true );
5635
5654
llvm::SmallVector<Identifier, 4 > namePieces;
5655
+ bool SignatureHasCodeCompletion = false ;
5636
5656
ParserResult<ParameterList> Params
5637
5657
= parseSingleParameterClause (ParameterContextKind::Initializer,
5638
5658
&namePieces, &DefaultArgs);
5639
5659
5660
+ SignatureHasCodeCompletion |= Params.hasCodeCompletion ();
5640
5661
if (Params.hasCodeCompletion () && !CodeCompletion) {
5641
5662
// Trigger delayed parsing, no need to continue.
5642
5663
return makeParserCodeCompletionStatus ();
@@ -5661,8 +5682,11 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
5661
5682
// Parse a 'where' clause if present, adding it to our GenericParamList.
5662
5683
if (Tok.is (tok::kw_where)) {
5663
5684
auto whereStatus = parseFreestandingGenericWhereClause (GenericParams);
5664
- if (whereStatus.shouldStopParsing ())
5685
+ SignatureHasCodeCompletion |= whereStatus.hasCodeCompletion ();
5686
+ if (whereStatus.hasCodeCompletion () && !CodeCompletion) {
5687
+ // Trigger delayed parsing, no need to continue.
5665
5688
return whereStatus;
5689
+ }
5666
5690
}
5667
5691
5668
5692
auto *SelfDecl = ParamDecl::createUnboundSelf (ConstructorLoc, CurDeclContext);
@@ -5686,8 +5710,8 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
5686
5710
DefaultArgs.setFunctionContext (CD);
5687
5711
5688
5712
// Pass the function signature to code completion.
5689
- if (Params. hasCodeCompletion () )
5690
- CodeCompletion->setDelayedParsedDecl (CD);
5713
+ if (SignatureHasCodeCompletion )
5714
+ CodeCompletion->setParsedDecl (CD);
5691
5715
5692
5716
if (ConstructorsNotAllowed || Params.isParseError ()) {
5693
5717
// Tell the type checker not to touch this constructor.
0 commit comments