|
1 | 1 | import LanguageServerProtocol |
2 | 2 |
|
3 | 3 | public typealias CursorPosition = LanguageServerProtocol.Position |
4 | | -public typealias CursorRange = LanguageServerProtocol.LSPRange |
5 | 4 |
|
6 | 5 | public extension CursorPosition { |
| 6 | + static let zero = CursorPosition(line: 0, character: 0) |
7 | 7 | static var outOfScope: CursorPosition { .init(line: -1, character: -1) } |
8 | 8 | } |
9 | 9 |
|
| 10 | +public struct CursorRange: Codable, Hashable, Sendable { |
| 11 | + static let zero = CursorRange(start: .zero, end: .zero) |
| 12 | + |
| 13 | + public var start: CursorPosition |
| 14 | + public var end: CursorPosition |
| 15 | + |
| 16 | + public init(start: Position, end: Position) { |
| 17 | + self.start = start |
| 18 | + self.end = end |
| 19 | + } |
| 20 | + |
| 21 | + public init(startPair: (Int, Int), endPair: (Int, Int)) { |
| 22 | + self.start = Position(startPair) |
| 23 | + self.end = Position(endPair) |
| 24 | + } |
| 25 | + |
| 26 | + public func contains(_ position: Position) -> Bool { |
| 27 | + return position > start && position < end |
| 28 | + } |
| 29 | + |
| 30 | + public func intersects(_ other: LSPRange) -> Bool { |
| 31 | + return contains(other.start) || contains(other.end) |
| 32 | + } |
| 33 | + |
| 34 | + public var isEmpty: Bool { |
| 35 | + return start == end |
| 36 | + } |
| 37 | +} |
| 38 | + |
10 | 39 | public extension CursorRange { |
11 | 40 | static var outOfScope: CursorRange { .init(start: .outOfScope, end: .outOfScope) } |
12 | 41 | static func cursor(_ position: CursorPosition) -> CursorRange { |
|
0 commit comments