mirror of
https://github.com/github/semantic.git
synced 2024-12-21 13:51:44 +03:00
Share the computation of the first line.
This commit is contained in:
parent
406001f25f
commit
13b6445309
@ -121,8 +121,9 @@ sourceSpanToRange source SourceSpan{..} = Range start end
|
|||||||
-- | Compute the 'SourceSpan' corresponding to a given byte 'Range' in a 'Source'.
|
-- | Compute the 'SourceSpan' corresponding to a given byte 'Range' in a 'Source'.
|
||||||
rangeToSourceSpan :: Source -> Range -> SourceSpan
|
rangeToSourceSpan :: Source -> Range -> SourceSpan
|
||||||
rangeToSourceSpan source (Range rangeStart rangeEnd) = SourceSpan startPos endPos
|
rangeToSourceSpan source (Range rangeStart rangeEnd) = SourceSpan startPos endPos
|
||||||
where startPos = SourcePos (Prologue.length before + 1) (rangeStart - start firstRange + 1)
|
where startPos = SourcePos (firstLine + 1) (rangeStart - start firstRange + 1)
|
||||||
endPos = SourcePos (Prologue.length before + Prologue.length lineRanges) (rangeEnd - start lastRange + 1)
|
endPos = SourcePos (firstLine + Prologue.length lineRanges) (rangeEnd - start lastRange + 1)
|
||||||
|
firstLine = Prologue.length before
|
||||||
(before, rest) = span ((< rangeStart) . end) (actualLineRanges source)
|
(before, rest) = span ((< rangeStart) . end) (actualLineRanges source)
|
||||||
(lineRanges, _) = span ((<= rangeEnd) . start) rest
|
(lineRanges, _) = span ((<= rangeEnd) . start) rest
|
||||||
Just firstRange = getFirst (foldMap (First . Just) lineRanges)
|
Just firstRange = getFirst (foldMap (First . Just) lineRanges)
|
||||||
|
Loading…
Reference in New Issue
Block a user