on 8bce2dd help sign in
40 lines 1.5 kB history raw
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE DuplicateRecordFields #-}
5{-# LANGUAGE RankNTypes #-}
6module Development.IDE.LSP.Server
7 ( WithMessage(..)
8 , PartialHandlers(..)
9 ) where
12import Data.Default
14import Language.Haskell.LSP.Types
15import qualified Language.Haskell.LSP.Core as LSP
16import qualified Language.Haskell.LSP.Messages as LSP
17import Development.IDE.Core.Service
20data WithMessage = WithMessage
21 {withResponse :: forall m req resp . (Show m, Show req) =>
22 (ResponseMessage resp -> LSP.FromServerMessage) -> -- how to wrap a response
23 (LSP.LspFuncs () -> IdeState -> req -> IO resp) -> -- actual work
24 Maybe (LSP.Handler (RequestMessage m req resp))
25 ,withNotification :: forall m req . (Show m, Show req) =>
26 Maybe (LSP.Handler (NotificationMessage m req)) -> -- old notification handler
27 (LSP.LspFuncs () -> IdeState -> req -> IO ()) -> -- actual work
28 Maybe (LSP.Handler (NotificationMessage m req))
29 }
31newtype PartialHandlers = PartialHandlers (WithMessage -> LSP.Handlers -> IO LSP.Handlers)
33instance Default PartialHandlers where
34 def = PartialHandlers $ \_ x -> pure x
36instance Semigroup PartialHandlers where
37 PartialHandlers a <> PartialHandlers b = PartialHandlers $ \w x -> a w x >>= b w
39instance Monoid PartialHandlers where
40 mempty = def