[sourcekitd] Fix cursor resolving when pointing inside string interpolations of return statements

rdar://36336648
This commit is contained in:
Argyrios Kyrtzidis
2018-01-09 11:46:15 -08:00
parent 4035b9bf98
commit 14116f84a1
3 changed files with 31 additions and 5 deletions

View File

@@ -149,9 +149,17 @@ bool CursorInfoResolver::walkToDeclPost(Decl *D) {
}
bool CursorInfoResolver::walkToStmtPre(Stmt *S) {
// Getting the character range for the statement, to account for interpolation
// strings. The token range for the interpolation string is the whole string,
// with begin/end locations pointing at the beginning of the string, so if
// there is a token location inside the string, it will seem as if it is out
// of the source range, unless we convert to character range.
// FIXME: Even implicit Stmts should have proper ranges that include any
// non-implicit Stmts (fix Stmts created for lazy vars).
if (!S->isImplicit() && !rangeContainsLoc(S->getSourceRange()))
if (!S->isImplicit() &&
!rangeContainsLoc(Lexer::getCharSourceRangeFromSourceRange(
getSourceMgr(), S->getSourceRange())))
return false;
return !tryResolve(S);
}
@@ -249,6 +257,14 @@ SourceManager &NameMatcher::getSourceMgr() const {
return SrcFile.getASTContext().SourceMgr;
}
bool CursorInfoResolver::rangeContainsLoc(SourceRange Range) const {
return getSourceMgr().rangeContainsTokenLoc(Range, LocToResolve);
}
bool CursorInfoResolver::rangeContainsLoc(CharSourceRange Range) const {
return Range.contains(LocToResolve);
}
std::vector<ResolvedLoc> NameMatcher::resolve(ArrayRef<UnresolvedLoc> Locs, ArrayRef<Token> Tokens) {
// Note the original indices and sort them in reverse source order