mirror of
https://github.com/github/semantic.git
synced 2024-12-21 05:41:54 +03:00
📝 rangeToSourceSpan & sourceSpanToRange.
This commit is contained in:
parent
9f847da265
commit
96469f0bd1
@ -110,7 +110,7 @@ actualLineRangesWithin :: Range -> Source -> [Range]
|
||||
actualLineRangesWithin range = Prologue.drop 1 . scanl toRange (Range (start range) (start range)) . actualLines . slice range
|
||||
where toRange previous string = Range (end previous) $ end previous + B.length (sourceText string)
|
||||
|
||||
-- | Compute the character range given a Source and a SourceSpan.
|
||||
-- | Compute the byte 'Range' corresponding to a given 'SourceSpan' in a 'Source'.
|
||||
sourceSpanToRange :: Source -> SourceSpan -> Range
|
||||
sourceSpanToRange source SourceSpan{..} = Range start end
|
||||
where start = pred (sumLengths leadingRanges + column spanStart)
|
||||
@ -118,6 +118,7 @@ sourceSpanToRange source SourceSpan{..} = Range start end
|
||||
(leadingRanges, remainingRanges) = splitAt (pred (line spanStart)) (actualLineRanges source)
|
||||
sumLengths = sum . fmap rangeLength
|
||||
|
||||
-- | Compute the 'SourceSpan' corresponding to a given byte 'Range' in a 'Source'.
|
||||
rangeToSourceSpan :: Source -> Range -> SourceSpan
|
||||
rangeToSourceSpan source (Range rangeStart rangeEnd) = SourceSpan startPos endPos
|
||||
where startPos = SourcePos (succ (Prologue.length before)) (succ (rangeStart - start firstRange))
|
||||
|
Loading…
Reference in New Issue
Block a user