@@ -11,6 +11,7 @@ module Development.IDE.LSP.LanguageServer
1111 , Log (.. )
1212 , ThreadQueue
1313 , runWithWorkerThreads
14+ , Communication (.. )
1415 ) where
1516
1617import Control.Concurrent.STM
@@ -27,16 +28,19 @@ import Ide.Types (traceWithSpan)
2728import Language.LSP.Protocol.Message
2829import Language.LSP.Protocol.Types
2930import qualified Language.LSP.Server as LSP
30- import System.IO
3131import UnliftIO.Async
3232import UnliftIO.Concurrent
3333import UnliftIO.Directory
3434import UnliftIO.Exception
3535
3636import qualified Colog.Core as Colog
3737import Control.Exception (BlockedIndefinitelyOnMVar (.. ))
38+ import Control.Exception.Backtrace (BacktraceMechanism (.. ),
39+ setBacktraceMechanismState )
3840import Control.Monad.IO.Unlift (MonadUnliftIO )
3941import Control.Monad.Trans.Cont (evalContT )
42+ import Data.ByteString
43+ import Data.ByteString.Lazy
4044import Development.IDE.Core.IdeConfiguration
4145import Development.IDE.Core.Shake hiding (Log )
4246import Development.IDE.Core.Tracing
@@ -82,13 +86,17 @@ instance Pretty Log where
8286 LogLspServer msg -> pretty msg
8387 LogServerShutdownMessage -> " Received shutdown message"
8488
89+ data Communication
90+ = Communication
91+ { inwards :: IO StrictByteString
92+ , outwards :: LazyByteString -> IO ()
93+ }
8594
8695runLanguageServer
8796 :: forall config a m . (Show config )
8897 => Recorder (WithPriority Log )
8998 -> LSP. Options
90- -> Handle -- input
91- -> Handle -- output
99+ -> Communication
92100 -> config
93101 -> (config -> Value -> Either T. Text config )
94102 -> (config -> m config () )
@@ -97,7 +105,7 @@ runLanguageServer
97105 LSP. Handlers (m config ),
98106 (LanguageContextEnv config , a ) -> m config <~> IO ))
99107 -> IO ()
100- runLanguageServer recorder options inH outH defaultConfig parseConfig onConfigChange setup = do
108+ runLanguageServer recorder options comm defaultConfig parseConfig onConfigChange setup = do
101109 -- This MVar becomes full when the server thread exits or we receive exit message from client.
102110 -- LSP server will be canceled when it's full.
103111 clientMsgVar <- newEmptyMVar
@@ -120,11 +128,11 @@ runLanguageServer recorder options inH outH defaultConfig parseConfig onConfigCh
120128 lspCologAction = toCologActionWithPrio (cmapWithPrio LogLspServer recorder)
121129
122130 void $ untilMVar clientMsgVar $
123- void $ LSP. runServerWithHandles
131+ void $ LSP. runServerWith
124132 lspCologAction
125133 lspCologAction
126- inH
127- outH
134+ (inwards comm)
135+ (outwards comm)
128136 serverDefinition
129137
130138setupLSP ::
0 commit comments