Skip to content

[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

Merged
merged 10 commits into from
May 11, 2017
Merged

[CodeCompletion] Provide basic code completion support for Swift KeyPath. rdar://31768743 #9467

merged 10 commits into from
May 11, 2017

Conversation

nkcsgexi
Copy link
Contributor

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].

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi requested a review from benlangmuir May 10, 2017 23:24
// 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
Copy link
Contributor

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 ??

Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question for rootResult

Copy link
Contributor Author

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.

Copy link
Contributor

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.

case CompletionKind::SwiftKeyPath: {
Lookup.setHaveDot(DotLoc);
Lookup.setIsSwiftKeyPathExpr();
Lookup.getValueExprCompletions((*ExprType)->getAs<BoundGenericType>()->
Copy link
Contributor

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]?

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@benlangmuir
Copy link
Contributor

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!

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi merged commit e997128 into swiftlang:master May 11, 2017
@nkcsgexi nkcsgexi deleted the code-complete-key-path branch May 11, 2017 04:48
nkcsgexi added a commit that referenced this pull request May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants