forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportedFromLSP.swift
More file actions
44 lines (34 loc) · 1.24 KB
/
ExportedFromLSP.swift
File metadata and controls
44 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import LanguageServerProtocol
public typealias CursorPosition = LanguageServerProtocol.Position
public extension CursorPosition {
static let zero = CursorPosition(line: 0, character: 0)
static var outOfScope: CursorPosition { .init(line: -1, character: -1) }
}
public struct CursorRange: Codable, Hashable, Sendable {
static let zero = CursorRange(start: .zero, end: .zero)
public var start: CursorPosition
public var end: CursorPosition
public init(start: Position, end: Position) {
self.start = start
self.end = end
}
public init(startPair: (Int, Int), endPair: (Int, Int)) {
self.start = Position(startPair)
self.end = Position(endPair)
}
public func contains(_ position: Position) -> Bool {
return position > start && position < end
}
public func intersects(_ other: LSPRange) -> Bool {
return contains(other.start) || contains(other.end)
}
public var isEmpty: Bool {
return start == end
}
}
public extension CursorRange {
static var outOfScope: CursorRange { .init(start: .outOfScope, end: .outOfScope) }
static func cursor(_ position: CursorPosition) -> CursorRange {
return .init(start: position, end: position)
}
}