[LIGO-40] Implement LSP range cconversion function

Problem: We need to be able to convert squirrel ranges to lsp
specific ones.

Solution: Add `toLSPRange` function.
This commit is contained in:
Anton Myasnikov 2020-08-25 19:13:23 +03:00
parent 283f41738d
commit 0b1590e324
No known key found for this signature in database
GPG Key ID: FEB685E6DAA0A95F

View File

@ -7,13 +7,16 @@
module Range
( Range(..)
, HasRange(..)
, toLSPRange
, cutOut
, point
)
where
import qualified Data.ByteString as BS
import qualified Language.Haskell.LSP.Types as LSP (Position (..), Range (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Text (Text)
import Data.Text.Encoding
@ -54,6 +57,16 @@ instance HasRange Range where
instance Contains Range xs => HasRange (Product xs) where
getRange = getElem
-- | Convert `squirrel` range to `haskell-lsp` range.
toLSPRange :: Range -> LSP.Range
toLSPRange Range
{ rStart = (rsl, rsc, _)
, rFinish = (rfl, rfc, _)
} = LSP.Range
{ LSP._start = LSP.Position { LSP._line = rsl, LSP._character = rsc }
, LSP._end = LSP.Position { LSP._line = rfl, LSP._character = rfc }
}
-- | Extract textual representation of given range.
cutOut :: Range -> ByteString -> Text
cutOut (Range (_, _, s) (_, _, f) _) bs =
@ -73,4 +86,4 @@ instance Eq Range where
(l, c, r, d, f) == (l1, c1, r1, d1, f1)
instance (Contains Range xs, Eq (Product xs)) => Lattice (Product xs) where
a `leq` b = getElem @Range a `leq` getElem @Range b
a `leq` b = getElem @Range a `leq` getElem @Range b