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