diff --git a/Sources/LanguageServerProtocol/BasicStructures.swift b/Sources/LanguageServerProtocol/BasicStructures.swift index 17c5887..37f5740 100644 --- a/Sources/LanguageServerProtocol/BasicStructures.swift +++ b/Sources/LanguageServerProtocol/BasicStructures.swift @@ -33,6 +33,16 @@ extension Position: Comparable { } } +extension Range where Bound == Position { + public init(_ start: Position, _ end: Position) { + self.init(uncheckedBounds: (lower: start, upper: end)) + } + + public init(_ range: LSPRange) { + self.init(uncheckedBounds: (lower: range.start, upper: range.end)) + } +} + public struct LSPRange: Codable, Hashable, Sendable { public static let zero = LSPRange(start: .zero, end: .zero) @@ -49,6 +59,11 @@ public struct LSPRange: Codable, Hashable, Sendable { self.end = Position(endPair) } + public init(_ other: Range) { + self.start = other.lowerBound + self.end = other.upperBound + } + public func contains(_ position: Position) -> Bool { return position > start && position < end }