Skip to content

Commit 75826fb

Browse files
committed
Add helper instances and functions
1 parent b12f16a commit 75826fb

File tree

6 files changed

+45
-0
lines changed

6 files changed

+45
-0
lines changed

lsp-types/lsp-types.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ library
7171
, base >=4.11 && <5
7272
, binary
7373
, containers
74+
, data-default
7475
, deepseq
7576
, Diff >=0.2
7677
, dlist
@@ -114,6 +115,7 @@ library
114115
Language.LSP.Protocol.Message.Registration
115116
Language.LSP.Protocol.Message.Types
116117
Language.LSP.Protocol.Types.Common
118+
Language.LSP.Protocol.Types.CustomInstances
117119
Language.LSP.Protocol.Types.Edit
118120
Language.LSP.Protocol.Types.Lens
119121
Language.LSP.Protocol.Types.Location

lsp-types/src/Language/LSP/Protocol/Message/Lens.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-#LANGUAGE TemplateHaskell #-}
2+
{-# OPTIONS_GHC -Wno-orphans #-}
23

34
module Language.LSP.Protocol.Message.Lens where
45

lsp-types/src/Language/LSP/Protocol/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module Language.LSP.Protocol.Types (
2222
, module SemanticTokens
2323
-- * Main LSP types and functions
2424
, module Generated
25+
-- ** Custom instances for the generated types
26+
, module CustomInstances
2527
) where
2628

2729
import Language.LSP.Protocol.Internal.Types as Generated
@@ -35,3 +37,4 @@ import Language.LSP.Protocol.Types.Singletons as Singletons
3537
import Language.LSP.Protocol.Types.Uri as Uri
3638
import Language.LSP.Protocol.Types.Uri.OsPath as Uri
3739
import Language.LSP.Protocol.Types.Edit as Edits
40+
import Language.LSP.Protocol.Types.CustomInstances as CustomInstances

lsp-types/src/Language/LSP/Protocol/Types/Common.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Language.LSP.Protocol.Types.Common (
1818
, Null (..)
1919
, absorbNull
2020
, nullToMaybe
21+
, maybeToNull
2122
, (.=?)
2223
) where
2324

@@ -123,6 +124,16 @@ nullToMaybe :: a |? Null -> Maybe a
123124
nullToMaybe (InL a) = Just a
124125
nullToMaybe (InR _) = Nothing
125126

127+
maybeToNull :: Maybe a -> a |? Null
128+
maybeToNull (Just x) = InL x
129+
maybeToNull Nothing = InR Null
130+
131+
instance Semigroup s => Semigroup (s |? Null) where
132+
InL x <> InL y = InL (x <> y)
133+
InL x <> InR _ = InL x
134+
InR _ <> InL x = InL x
135+
InR _ <> InR y = InR y
136+
126137
-- We use String so we can use fromString on it to get a key that works
127138
-- in both aeson-1 and aeson-2
128139
-- | Include a value in an JSON object optionally, omitting it if it is 'Nothing'.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# OPTIONS_GHC -Wno-orphans #-}
2+
module Language.LSP.Protocol.Types.CustomInstances where
3+
4+
import Language.LSP.Protocol.Internal.Types
5+
import Data.Default
6+
import Data.Hashable
7+
import Data.Semigroup ()
8+
9+
instance Semigroup WorkspaceEdit where
10+
(WorkspaceEdit a b c) <> (WorkspaceEdit a' b' c') = WorkspaceEdit (a <> a') (b <> b') (c <> c')
11+
instance Monoid WorkspaceEdit where
12+
mempty = WorkspaceEdit Nothing Nothing Nothing
13+
14+
instance Hashable Location
15+
instance Hashable Range
16+
instance Hashable Position
17+
18+
instance Default ClientCapabilities where
19+
def = ClientCapabilities (Just def) (Just def) (Just def) (Just def) (Just def) Nothing
20+
21+
instance Default WorkspaceClientCapabilities
22+
instance Default TextDocumentClientCapabilities
23+
instance Default NotebookDocumentClientCapabilities where
24+
def = NotebookDocumentClientCapabilities def
25+
instance Default NotebookDocumentSyncClientCapabilities
26+
instance Default WindowClientCapabilities
27+
instance Default GeneralClientCapabilities

lsp-types/src/Language/LSP/Protocol/Types/Lens.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-#LANGUAGE TemplateHaskell #-}
2+
{-# OPTIONS_GHC -Wno-orphans #-}
23

34
module Language.LSP.Protocol.Types.Lens where
45

0 commit comments

Comments
 (0)