Skip to content

Commit 4603b67

Browse files
committed
[CodeComplete] Fix issue completing type in generic signature
Due to #36552, parsing the code completion token as a type inside a generic parameter list no longer fails. Instead, it consumes the code completion token as a type identifier. However, since `parseExprIdentifer` does not return a `ParserStatus`, the information whether a code completion token was consumed gets lost, causing `setCodeCompletionDelayedDeclState` to not be called and thus no code completion results show up. To resolve this, make `parseExprIdentifier` return its `ParserStatus` through a `ParserResult`. Fixes rdar://76335452 [SR-14432]
1 parent 5cf19e4 commit 4603b67

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Diff for: include/swift/Parse/Parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ class Parser {
15821582
DeclNameRef parseDeclNameRef(DeclNameLoc &loc, const Diagnostic &diag,
15831583
DeclNameOptions flags);
15841584

1585-
Expr *parseExprIdentifier();
1585+
ParserResult<Expr> parseExprIdentifier();
15861586
Expr *parseExprEditorPlaceholder(Token PlaceholderTok,
15871587
Identifier PlaceholderId);
15881588

Diff for: lib/Parse/ParseExpr.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
15451545

15461546
LLVM_FALLTHROUGH;
15471547
case tok::kw_Self: // Self
1548-
return makeParserResult(parseExprIdentifier());
1548+
return parseExprIdentifier();
15491549

15501550
case tok::kw_Any: { // Any
15511551
ExprContext.setCreateSyntax(SyntaxKind::TypeExpr);
@@ -2192,7 +2192,8 @@ DeclNameRef Parser::parseDeclNameRef(DeclNameLoc &loc,
21922192

21932193
/// expr-identifier:
21942194
/// unqualified-decl-name generic-args?
2195-
Expr *Parser::parseExprIdentifier() {
2195+
ParserResult<Expr> Parser::parseExprIdentifier() {
2196+
ParserStatus status;
21962197
assert(Tok.isAny(tok::identifier, tok::kw_self, tok::kw_Self));
21972198
SyntaxParsingContext IDSyntaxContext(SyntaxContext,
21982199
SyntaxKind::IdentifierExpr);
@@ -2217,8 +2218,9 @@ Expr *Parser::parseExprIdentifier() {
22172218
if (canParseAsGenericArgumentList()) {
22182219
SyntaxContext->createNodeInPlace(SyntaxKind::IdentifierExpr);
22192220
SyntaxContext->setCreateSyntax(SyntaxKind::SpecializeExpr);
2220-
auto argStat = parseGenericArguments(args, LAngleLoc, RAngleLoc);
2221-
if (argStat.isErrorOrHasCompletion())
2221+
auto argStatus = parseGenericArguments(args, LAngleLoc, RAngleLoc);
2222+
status |= argStatus;
2223+
if (argStatus.isErrorOrHasCompletion())
22222224
diagnose(LAngleLoc, diag::while_parsing_as_left_angle_bracket);
22232225

22242226
// The result can be empty in error cases.
@@ -2227,7 +2229,8 @@ Expr *Parser::parseExprIdentifier() {
22272229

22282230
if (name.getBaseName().isEditorPlaceholder()) {
22292231
IDSyntaxContext.setCreateSyntax(SyntaxKind::EditorPlaceholderExpr);
2230-
return parseExprEditorPlaceholder(IdentTok, name.getBaseIdentifier());
2232+
return makeParserResult(
2233+
status, parseExprEditorPlaceholder(IdentTok, name.getBaseIdentifier()));
22312234
}
22322235

22332236
auto refKind = DeclRefKind::Ordinary;
@@ -2237,7 +2240,7 @@ Expr *Parser::parseExprIdentifier() {
22372240
E = UnresolvedSpecializeExpr::create(Context, E, LAngleLoc, args,
22382241
RAngleLoc);
22392242
}
2240-
return E;
2243+
return makeParserResult(status, E);
22412244
}
22422245

22432246
Expr *Parser::parseExprEditorPlaceholder(Token PlaceholderTok,
@@ -2508,7 +2511,9 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
25082511
// If this is the simple case, then the identifier is both the name and
25092512
// the expression to capture.
25102513
name = Context.getIdentifier(Tok.getText());
2511-
initializer = parseExprIdentifier();
2514+
auto initializerResult = parseExprIdentifier();
2515+
status |= initializerResult;
2516+
initializer = initializerResult.get();
25122517

25132518
// It is a common error to try to capture a nested field instead of just
25142519
// a local name, reject it with a specific error message.

Diff for: test/IDE/complete_generic_param.swift

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INHERIT4 | %FileCheck %s -check-prefix=INHERIT
55
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INHERIT5 | %FileCheck %s -check-prefix=INHERIT
66
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INHERIT6 | %FileCheck %s -check-prefix=INHERIT
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TYPE_PARAM
8+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SECOND_GENERIC_TYPE_PARAM | %FileCheck %s -check-prefix=GENERIC_TYPE_PARAM
79

810
class C1{}
911
protocol P1{}
@@ -34,3 +36,12 @@ class C3 {
3436
// INHERIT-NOT: ValueInt1
3537
// INHERIT-NOT: ValueString2
3638
// INHERIT-NOT: TopLevelFunc
39+
40+
41+
class Sr14432<T, U> {}
42+
43+
_ = Sr14432<#^GENERIC_TYPE_PARAM^# >()
44+
_ = Sr14432<SomeType, #^SECOND_GENERIC_TYPE_PARAM^# >()
45+
// GENERIC_TYPE_PARAM: Begin completions
46+
// GENERIC_TYPE_PARAM-DAG: Decl[Class]/CurrModule: C1[#C1#];
47+
// GENERIC_TYPE_PARAM: End completions

0 commit comments

Comments
 (0)