Skip to content

Commit 98ba7cc

Browse files
authored
Merge pull request #486 from joyfulmantis/helper-functions
Add helper instances and functions
2 parents 5158e0b + 19b7425 commit 98ba7cc

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-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
@@ -122,6 +123,7 @@ library
122123
Language.LSP.Protocol.Types.Location
123124
Language.LSP.Protocol.Types.LspEnum
124125
Language.LSP.Protocol.Types.MarkupContent
126+
Language.LSP.Protocol.Types.Orphans
125127
Language.LSP.Protocol.Types.Progress
126128
Language.LSP.Protocol.Types.SemanticTokens
127129
Language.LSP.Protocol.Types.Singletons

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
@@ -24,6 +24,8 @@ module Language.LSP.Protocol.Types (
2424
, module WatchKinds
2525
-- * Main LSP types and functions
2626
, module Generated
27+
-- ** Orphan instances for the generated types
28+
, module Orphans
2729
) where
2830

2931
import Language.LSP.Protocol.Internal.Types as Generated
@@ -37,4 +39,5 @@ import Language.LSP.Protocol.Types.Singletons as Singletons
3739
import Language.LSP.Protocol.Types.Uri as Uri
3840
import Language.LSP.Protocol.Types.Uri.OsPath as Uri
3941
import Language.LSP.Protocol.Types.Edit as Edits
42+
import Language.LSP.Protocol.Types.Orphans as Orphans
4043
import Language.LSP.Protocol.Types.WatchKinds as WatchKinds

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Language.LSP.Protocol.Types.Common (
1919
, Null (..)
2020
, absorbNull
2121
, nullToMaybe
22+
, maybeToNull
2223
, (.=?)
2324
) where
2425

@@ -153,6 +154,17 @@ nullToMaybe :: a |? Null -> Maybe a
153154
nullToMaybe (InL a) = Just a
154155
nullToMaybe (InR _) = Nothing
155156

157+
maybeToNull :: Maybe a -> a |? Null
158+
maybeToNull (Just x) = InL x
159+
maybeToNull Nothing = InR Null
160+
161+
-- This is equivalent to the instance for 'Maybe s'
162+
instance Semigroup s => Semigroup (s |? Null) where
163+
InL x <> InL y = InL (x <> y)
164+
InL x <> InR _ = InL x
165+
InR _ <> InL x = InL x
166+
InR _ <> InR y = InR y
167+
156168
-- We use String so we can use fromString on it to get a key that works
157169
-- in both aeson-1 and aeson-2
158170
-- | Include a value in an JSON object optionally, omitting it if it is 'Nothing'.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{-# OPTIONS_GHC -Wno-orphans #-}
2+
module Language.LSP.Protocol.Types.Orphans where
3+
4+
import Language.LSP.Protocol.Internal.Types
5+
import Data.Default
6+
import Data.Semigroup ()
7+
8+
instance Semigroup WorkspaceEdit where
9+
(WorkspaceEdit a b c) <> (WorkspaceEdit a' b' c') = WorkspaceEdit (a <> a') (b <> b') (c <> c')
10+
instance Monoid WorkspaceEdit where
11+
mempty = WorkspaceEdit Nothing Nothing Nothing
12+
13+
instance Default ClientCapabilities where
14+
def = ClientCapabilities def def def def def Nothing
15+
instance Default WorkspaceClientCapabilities
16+
instance Default TextDocumentClientCapabilities
17+
instance Default NotebookDocumentClientCapabilities where
18+
instance Default NotebookDocumentSyncClientCapabilities
19+
instance Default WindowClientCapabilities
20+
instance Default GeneralClientCapabilities

0 commit comments

Comments
 (0)