-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Provide basic code completion support for Swift KeyPath. rdar://31768743 #9467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test |
// PERSON-MEMBER-OPT: Begin completions, 7 items | ||
// PERSON-MEMBER-OPT-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.name[#String#]; name=name | ||
// PERSON-MEMBER-OPT-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.friends[#[Person]#]; name=friends | ||
// PERSON-MEMBER-OPT-NEXT: Decl[InstanceVar]/CurrNominal/Erase[1]: ?.bestFriend[#Person?#]; name=bestFriend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these incorrect for PART_4? The result will be \Person.bestFriend??.name
, etc. Shouldn't it be just one ?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generic property keyPath isn't landed in the compiler yet. I will drop the test case.
lib/Parse/ParseExpr.cpp
Outdated
@@ -1136,8 +1139,17 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic, | |||
|
|||
// Handle "x.<tab>" for code completion. | |||
if (Tok.is(tok::code_complete)) { | |||
if (CodeCompletion && Result.isNonNull()) | |||
if (CodeCompletion && Result.isNonNull()) { | |||
if (InSwiftKeyPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, please put {}
braces around these since they're split on several lines and it's important to know that the completeDoctExpr
is not part of the else
.
@@ -525,6 +525,7 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) { | |||
ParserResult<Expr> Parser::parseExprKeyPath() { | |||
// Consume '\'. | |||
SourceLoc backslashLoc = consumeToken(tok::backslash); | |||
llvm::SaveAndRestore<SourceLoc> slashLoc(SwiftKeyPathSlashLoc, backslashLoc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use backslashLoc
directly? It's not being modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This basically to save SwiftKeyPathSlashLoc in the parser context so parseExprPostfixSuffix can use it to create an instance of KeyPathExpr.
@@ -538,6 +539,8 @@ ParserResult<Expr> Parser::parseExprKeyPath() { | |||
} | |||
|
|||
if (startsWithSymbol(Tok, '.')) { | |||
llvm::SaveAndRestore<Expr*> S(SwiftKeyPathRoot, rootResult.getPtrOrNull()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question for rootResult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are not using SaveAndRestore, we are not able to use this part in parseExprPostfixSuffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry I misread this. For some reason I didn't notice they were in completely different functions ,etc.
lib/IDE/CodeCompletion.cpp
Outdated
case CompletionKind::SwiftKeyPath: { | ||
Lookup.setHaveDot(DotLoc); | ||
Lookup.setIsSwiftKeyPathExpr(); | ||
Lookup.getValueExprCompletions((*ExprType)->getAs<BoundGenericType>()-> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on here with BoundGenericType
and getGenericArgs()[1]
?
@swift-ci please smoke test |
Maybe put a FIXME in the test for the missing case so it's obvious that PART 4 isn't actually checking anything. Otherwise, LGTM thanks! |
@swift-ci please smoke test |
…ath. rdar://31768743 (#9467)
This patch starts libIDE support for code completing keyPath expression; after each
.
in key path component, code completion provides type-sensitive member properties and subscripts. This patch doesn't implement code completion for contextual-inferred keyPath root type like\.property.[0]
.