LSP: Add Range::contains(Range)

Change-Id: I762f5582cd00e6ee00a0c345a1b9ba4de8231538
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-04-28 10:14:12 +02:00
parent fa23183460
commit 794babeb2c
2 changed files with 22 additions and 2 deletions

View File

@@ -312,6 +312,15 @@ Range::Range(const QTextCursor &cursor)
setEnd(Position(line - 1, character - 1));
}
bool Range::contains(const Range &other) const
{
if (start() > other.start())
return false;
if (end() < other.end())
return false;
return true;
}
bool Range::overlaps(const Range &range) const
{
return contains(range.start()) || contains(range.end());

View File

@@ -90,10 +90,20 @@ public:
QTextCursor toTextCursor(QTextDocument *doc) const;
};
static bool operator<=(const Position &first, const Position &second)
inline bool operator<(const Position &first, const Position &second)
{
return first.line() < second.line()
|| (first.line() == second.line() && first.character() <= second.character());
|| (first.line() == second.line() && first.character() < second.character());
}
inline bool operator>(const Position &first, const Position &second)
{
return second < first;
}
inline bool operator<=(const Position &first, const Position &second)
{
return !(first > second);
}
class LANGUAGESERVERPROTOCOL_EXPORT Range : public JsonObject
@@ -113,6 +123,7 @@ public:
void setEnd(const Position &end) { insert(endKey, end); }
bool contains(const Position &pos) const { return start() <= pos && pos <= end(); }
bool contains(const Range &other) const;
bool overlaps(const Range &range) const;
bool isValid() const override