From 26f180d6e13be560001489a7ac374e35722ed9eb Mon Sep 17 00:00:00 2001 From: Oliver Madine <30090176+OliverMadine@users.noreply.github.com> Date: Sun, 3 Apr 2022 23:46:07 +0100 Subject: [PATCH] hashable instance for location, range, position --- lsp-types/src/Language/LSP/Types/Common.hs | 3 +++ lsp-types/src/Language/LSP/Types/Location.hs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lsp-types/src/Language/LSP/Types/Common.hs b/lsp-types/src/Language/LSP/Types/Common.hs index fdc1ad04d..36ad58d43 100644 --- a/lsp-types/src/Language/LSP/Types/Common.hs +++ b/lsp-types/src/Language/LSP/Types/Common.hs @@ -18,6 +18,7 @@ module Language.LSP.Types.Common ( import Control.Applicative import Control.DeepSeq import Data.Aeson +import Data.Hashable import Data.Int (Int32) import Data.Mod.Word import Text.Read (Read(readPrec)) @@ -33,6 +34,8 @@ newtype UInt = UInt (Mod (2^31)) deriving stock (Generic) deriving anyclass (NFData) +instance Hashable UInt where hashWithSalt s (UInt n) = hashWithSalt s (unMod n) + instance Show UInt where show (UInt u) = show $ unMod u diff --git a/lsp-types/src/Language/LSP/Types/Location.hs b/lsp-types/src/Language/LSP/Types/Location.hs index 6adc16440..72f48e211 100644 --- a/lsp-types/src/Language/LSP/Types/Location.hs +++ b/lsp-types/src/Language/LSP/Types/Location.hs @@ -4,6 +4,7 @@ module Language.LSP.Types.Location where import Control.DeepSeq import Data.Aeson.TH +import Data.Hashable import GHC.Generics hiding (UInt) import Language.LSP.Types.Common import Language.LSP.Types.Uri @@ -26,6 +27,8 @@ data Position = instance NFData Position deriveJSON lspOptions ''Position +instance Hashable Position + -- --------------------------------------------------------------------- data Range = @@ -37,6 +40,8 @@ data Range = instance NFData Range deriveJSON lspOptions ''Range +instance Hashable Range + -- --------------------------------------------------------------------- data Location = @@ -48,6 +53,8 @@ data Location = instance NFData Location deriveJSON lspOptions ''Location +instance Hashable Location + -- --------------------------------------------------------------------- -- | Represents a link between a source and a target location.