Skip to content

[SourceKit] When Cursor infor resolves to the start of an expression, we always get the outermost expression. #10738

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 2 commits into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class SemaLocResolver : public SourceEntityWalker {
SourceLoc LocToResolve;
SemaToken SemaTok;
Type ContainerType;
llvm::SmallVector<Expr*, 4> TrailingExprStack;

public:
explicit SemaLocResolver(SourceFile &SrcFile) : SrcFile(SrcFile) { }
Expand Down Expand Up @@ -216,7 +217,6 @@ class SemaLocResolver : public SourceEntityWalker {
SourceLoc Loc, bool IsRef, Type Ty = Type());
bool tryResolve(ModuleEntity Mod, SourceLoc Loc);
bool tryResolve(Stmt *St);
bool tryResolve(Expr *Exp);
bool visitSubscriptReference(ValueDecl *D, CharSourceRange Range,
bool IsOpenBracket) override;
};
Expand Down
19 changes: 10 additions & 9 deletions lib/IDE/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ bool SemaLocResolver::tryResolve(Stmt *St) {
return false;
}

bool SemaLocResolver::tryResolve(Expr *Exp) {
if (!Exp->isImplicit() && Exp->getStartLoc() == LocToResolve) {
SemaTok = { Exp };
return true;
}
return false;
}

bool SemaLocResolver::visitSubscriptReference(ValueDecl *D, CharSourceRange Range,
bool IsOpenBracket) {
// We should treat both open and close brackets equally
Expand Down Expand Up @@ -193,14 +185,23 @@ bool SemaLocResolver::walkToExprPre(Expr *E) {
ContainerType = ME->getBase()->getType();
}
}

// Keep track of trailing expressions.
if (!E->isImplicit() && E->getStartLoc() == LocToResolve)
TrailingExprStack.push_back(E);
}
return true;
}

bool SemaLocResolver::walkToExprPost(Expr *E) {
if (isDone())
return false;
return !tryResolve(E);
if (!TrailingExprStack.empty() && TrailingExprStack.back() == E) {
// We return the outtermost expression in the token info.
SemaTok = { TrailingExprStack.front() };
return false;
}
return true;
}

bool SemaLocResolver::visitCallArgName(Identifier Name, CharSourceRange Range,
Expand Down