Skip to content

Add hashable instance for location, range, position #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lsp-types/src/Language/LSP/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lsp-types/src/Language/LSP/Types/Location.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +27,8 @@ data Position =
instance NFData Position
deriveJSON lspOptions ''Position

instance Hashable Position

-- ---------------------------------------------------------------------

data Range =
Expand All @@ -37,6 +40,8 @@ data Range =
instance NFData Range
deriveJSON lspOptions ''Range

instance Hashable Range

-- ---------------------------------------------------------------------

data Location =
Expand All @@ -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.
Expand Down