Skip to content

Commit d53a0af

Browse files
committed
Add documentation to position mapping
1 parent ae29b13 commit d53a0af

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/Haskell/Ide/Engine/Transport/LspStdio.hs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,58 @@ updatePositionMap uri changes = pluginGetFile "updatePositionMap: " uri $ \file
295295
return $ IdeResultOk ()
296296
where
297297
f (+/-) (J.Range (Position sl sc) (Position el ec)) txt p@(Position l c)
298+
299+
-- pos is before the change - unaffected
298300
| l < sl = Just p
301+
-- pos is somewhere after the changed line,
302+
-- move down the pos to keep it the same
299303
| l > el = Just $ Position l' c
304+
305+
{-
306+
LEGEND:
307+
0-9 char index
308+
x untouched char
309+
I/i inserted/replaced char
310+
. deleted char
311+
^ pos to be converted
312+
-}
313+
314+
{-
315+
012345 67
316+
xxxxxx xx
317+
^
318+
0123456789
319+
xxIIIIiixx
320+
^
321+
322+
pos is unchanged if before the edited range
323+
-}
300324
| l == sl && c <= sc = Just p
325+
326+
{-
327+
01234 56
328+
xxxxx xx
329+
^
330+
012345678
331+
xxIIIiixx
332+
^
333+
If pos is in the affected range move to after the range
334+
-}
301335
| l == sl && l == el && c <= nec && newL == 0 = Just $ Position l ec
336+
337+
{-
338+
01234 56
339+
xxxxx xx
340+
^
341+
012345678
342+
xxIIIiixx
343+
^
344+
If pos is after the affected range, update the char index
345+
to keep it in the same place
346+
-}
302347
| l == sl && l == el && c > nec && newL == 0 = Just $ Position l (c +/- (nec - sc))
348+
349+
-- oh well we tried ¯\_(ツ)_/¯
303350
| otherwise = Nothing
304351
where l' = l +/- dl
305352
dl = newL - oldL

0 commit comments

Comments
 (0)