Merge pull request #63714 from ahoppen/ahoppen/ideinspectiontarget-charsourcerange

[IDE] Check whether an AST node contains the IDE inspection point based on `CharSourceRange`
This commit is contained in:
swift-ci
2023-02-20 10:20:45 -08:00
committed by GitHub
9 changed files with 64 additions and 28 deletions

View File

@@ -214,6 +214,13 @@ public:
(isBeforeInBuffer(R.Start, Loc) && isBeforeInBuffer(Loc, R.End));
}
/// Returns true if range \c R contains the location \c Loc. The location
/// \c Loc should point at the beginning of the token.
bool rangeContainsTokenLoc(CharSourceRange R, SourceLoc Loc) const {
return Loc == R.getStart() || (isBeforeInBuffer(R.getStart(), Loc) &&
isBeforeInBuffer(Loc, R.getEnd()));
}
/// Returns true if range \c Enclosing contains the range \c Inner.
bool rangeContains(SourceRange Enclosing, SourceRange Inner) const {
return rangeContainsTokenLoc(Enclosing, Inner.Start) &&
@@ -221,10 +228,11 @@ public:
}
/// Returns true if range \p R contains the code-completion location, if any.
bool rangeContainsIDEInspectionTarget(SourceRange R) const {
return IDEInspectionTargetBufferID
? rangeContainsTokenLoc(R, getIDEInspectionTargetLoc())
: false;
bool rangeContainsIDEInspectionTarget(CharSourceRange R) const {
if (!IDEInspectionTargetBufferID) {
return false;
}
return rangeContainsTokenLoc(R, getIDEInspectionTargetLoc());
}
/// Returns the buffer ID for the specified *valid* location.