Skip to content

Commit 3081e81

Browse files
committed
Add Range manipulation functions
1 parent 15e53c4 commit 3081e81

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

hls-plugin-api/src/Ide/PluginUtils.hs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE TypeFamilies #-}
44
module Ide.PluginUtils
5-
( WithDeletions(..),
6-
getProcessID,
5+
( -- * LSP Range manipulation functions
76
normalize,
7+
extendNextLine,
8+
extendLineStart,
9+
WithDeletions(..),
10+
getProcessID,
811
makeDiffTextEdit,
912
makeDiffTextEditAdditive,
1013
diffText,
@@ -67,9 +70,27 @@ import qualified Text.Megaparsec.Char.Lexer as P
6770
-- ---------------------------------------------------------------------
6871

6972
-- | Extend to the line below and above to replace newline character.
73+
--
74+
-- >>> normalize (Range (Position 5 5) (Position 5 10))
75+
-- Range (Position 5 0) (Position 6 0)
7076
normalize :: Range -> Range
71-
normalize (Range (Position sl _) (Position el _)) =
72-
Range (Position sl 0) (Position (el + 1) 0)
77+
normalize = extendLineStart . extendNextLine
78+
79+
-- | Extend 'Range' to the start of the next line.
80+
--
81+
-- >>> extendNextLine (Range (Position 5 5) (Position 5 10))
82+
-- Range (Position 5 5) (Position 6 0)
83+
extendNextLine :: Range -> Range
84+
extendNextLine (Range s (Position el _)) =
85+
Range s (Position (el + 1) 0)
86+
87+
-- | Extend 'Range' to the start of the current line.
88+
--
89+
-- >>> extendLineStart (Range (Position 5 5) (Position 5 10))
90+
-- Range (Position 5 0) (Position 5 10)
91+
extendLineStart :: Range -> Range
92+
extendLineStart (Range (Position sl _) e) =
93+
Range (Position sl 0) e
7394

7495
-- ---------------------------------------------------------------------
7596

0 commit comments

Comments
 (0)