@@ -31,7 +31,8 @@ import Data.List
31
31
import qualified Data.Text as T
32
32
import qualified Data.Vector.Unboxed as V
33
33
import Language.LSP.Types (Position (Position ), Range (Range ),
34
- TextDocumentContentChangeEvent (TextDocumentContentChangeEvent ))
34
+ TextDocumentContentChangeEvent (TextDocumentContentChangeEvent ),
35
+ UInt )
35
36
36
37
-- | Either an exact position, or the range of text that was substituted
37
38
data PositionResult a
@@ -140,14 +141,17 @@ toCurrent (Range start@(Position startLine startColumn) end@(Position endLine en
140
141
where
141
142
lineDiff = linesNew - linesOld
142
143
linesNew = T. count " \n " t
143
- linesOld = endLine - startLine
144
+ linesOld = fromIntegral endLine - fromIntegral startLine
145
+ newEndColumn :: UInt
144
146
newEndColumn
145
- | linesNew == 0 = startColumn + T. length t
146
- | otherwise = T. length $ T. takeWhileEnd (/= ' \n ' ) t
147
+ | linesNew == 0 = fromIntegral $ fromIntegral startColumn + T. length t
148
+ | otherwise = fromIntegral $ T. length $ T. takeWhileEnd (/= ' \n ' ) t
149
+ newColumn :: UInt
147
150
newColumn
148
- | line == endLine = column + newEndColumn - endColumn
151
+ | line == endLine = fromIntegral $ ( fromIntegral column + newEndColumn) - fromIntegral endColumn
149
152
| otherwise = column
150
- newLine = line + lineDiff
153
+ newLine :: UInt
154
+ newLine = fromIntegral $ fromIntegral line + lineDiff
151
155
152
156
fromCurrent :: Range -> T. Text -> Position -> PositionResult Position
153
157
fromCurrent (Range start@ (Position startLine startColumn) end@ (Position endLine endColumn)) t (Position line column)
@@ -163,19 +167,23 @@ fromCurrent (Range start@(Position startLine startColumn) end@(Position endLine
163
167
where
164
168
lineDiff = linesNew - linesOld
165
169
linesNew = T. count " \n " t
166
- linesOld = endLine - startLine
167
- newEndLine = endLine + lineDiff
170
+ linesOld = fromIntegral endLine - fromIntegral startLine
171
+ newEndLine :: UInt
172
+ newEndLine = fromIntegral $ fromIntegral endLine + lineDiff
173
+ newEndColumn :: UInt
168
174
newEndColumn
169
- | linesNew == 0 = startColumn + T. length t
170
- | otherwise = T. length $ T. takeWhileEnd (/= ' \n ' ) t
175
+ | linesNew == 0 = fromIntegral $ fromIntegral startColumn + T. length t
176
+ | otherwise = fromIntegral $ T. length $ T. takeWhileEnd (/= ' \n ' ) t
177
+ newColumn :: UInt
171
178
newColumn
172
- | line == newEndLine = column - (newEndColumn - endColumn)
179
+ | line == newEndLine = fromIntegral $ ( fromIntegral column + fromIntegral endColumn) - newEndColumn
173
180
| otherwise = column
174
- newLine = line - lineDiff
181
+ newLine :: UInt
182
+ newLine = fromIntegral $ fromIntegral line - lineDiff
175
183
176
184
deltaFromDiff :: T. Text -> T. Text -> PositionDelta
177
185
deltaFromDiff (T. lines -> old) (T. lines -> new) =
178
- PositionDelta (lookupPos lnew o2nPrevs o2nNexts old2new) (lookupPos lold n2oPrevs n2oNexts new2old)
186
+ PositionDelta (lookupPos ( fromIntegral lnew) o2nPrevs o2nNexts old2new) (lookupPos ( fromIntegral lold) n2oPrevs n2oNexts new2old)
179
187
where
180
188
! lnew = length new
181
189
! lold = length old
@@ -194,17 +202,16 @@ deltaFromDiff (T.lines -> old) (T.lines -> new) =
194
202
f :: Int -> Int -> Int
195
203
f ! a ! b = if b == - 1 then a else b
196
204
197
- lookupPos :: Int -> V. Vector Int -> V. Vector Int -> V. Vector Int -> Position -> PositionResult Position
205
+ lookupPos :: UInt -> V. Vector Int -> V. Vector Int -> V. Vector Int -> Position -> PositionResult Position
198
206
lookupPos end prevs nexts xs (Position line col)
199
- | line < 0 = PositionRange (Position 0 0 ) (Position 0 0 )
200
- | line >= V. length xs = PositionRange (Position end 0 ) (Position end 0 )
201
- | otherwise = case V. unsafeIndex xs line of
207
+ | line >= fromIntegral (V. length xs) = PositionRange (Position end 0 ) (Position end 0 )
208
+ | otherwise = case V. unsafeIndex xs (fromIntegral line) of
202
209
- 1 ->
203
210
-- look for the previous and next lines that mapped successfully
204
- let ! prev = 1 + V. unsafeIndex prevs line
205
- ! next = V. unsafeIndex nexts line
206
- in PositionRange (Position prev 0 ) (Position next 0 )
207
- line' -> PositionExact (Position line' col)
211
+ let ! prev = 1 + V. unsafeIndex prevs ( fromIntegral line)
212
+ ! next = V. unsafeIndex nexts ( fromIntegral line)
213
+ in PositionRange (Position ( fromIntegral prev) 0 ) (Position ( fromIntegral next) 0 )
214
+ line' -> PositionExact (Position ( fromIntegral line') col)
208
215
209
216
-- Construct a mapping between lines in the diff
210
217
-- -1 for unsucessful mapping
0 commit comments