From 0b1590e32421fee8b074885498d4e567bcc122b9 Mon Sep 17 00:00:00 2001 From: Anton Myasnikov Date: Tue, 25 Aug 2020 19:13:23 +0300 Subject: [PATCH] [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. --- tools/lsp/squirrel/src/Range.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/lsp/squirrel/src/Range.hs b/tools/lsp/squirrel/src/Range.hs index 40f6cdd72..957aa7ee2 100644 --- a/tools/lsp/squirrel/src/Range.hs +++ b/tools/lsp/squirrel/src/Range.hs @@ -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 \ No newline at end of file + a `leq` b = getElem @Range a `leq` getElem @Range b