@@ -36,34 +36,35 @@ import Options
3636--------------------------------------------------------------------------------
3737
3838run :: Options -> IO Int
39- run alsOptions = do
40- env <- createInitEnv alsOptions
41- switchboard <- Switchboard. new env
42- case optViaTCP alsOptions of
39+ run options = do
40+ case optViaTCP options of
4341 Just port -> do
4442 void
4543 $ TCP. serve (TCP. Host " 127.0.0.1" ) (show port)
4644 $ \ (sock, _remoteAddr) -> do
47- writeChan (envLogChan env) " [Server] connection established"
45+ -- writeChan (envLogChan env) "[Server] connection established"
4846 handle <- socketToHandle sock ReadWriteMode
49- _ <- runServerWithHandles handle handle (serverDefn env switchboard )
47+ _ <- runServerWithHandles handle handle (serverDefn options )
5048 return ()
51- Switchboard. destroy switchboard
49+ -- Switchboard.destroy switchboard
5250 return 0
5351 Nothing -> do
54- runServer (serverDefn env switchboard )
52+ runServer (serverDefn options )
5553 where
56- serverDefn :: Env -> Switchboard -> ServerDefinition Config
57- serverDefn env switchboard = ServerDefinition
54+ serverDefn :: Options -> ServerDefinition Config
55+ serverDefn options = ServerDefinition
5856 { defaultConfig = initConfig
5957 , onConfigurationChange = \ old newRaw -> case JSON. fromJSON newRaw of
6058 JSON. Error s -> Left $ pack $ " Cannot parse server configuration: " <> s
6159 JSON. Success new -> Right new
6260 , doInitialize = \ ctxEnv _req -> do
61+ env <- runLspT ctxEnv (createInitEnv options)
62+ switchboard <- Switchboard. new env
6363 Switchboard. setupLanguageContextEnv switchboard ctxEnv
64- pure $ Right ctxEnv
64+ pure $ Right ( ctxEnv, env)
6565 , staticHandlers = handlers
66- , interpretHandler = \ ctxEnv -> Iso (runLspT ctxEnv . runServerM env) liftIO
66+ , interpretHandler = \ (ctxEnv, env) ->
67+ Iso (runLspT ctxEnv . runServerM env) liftIO
6768 , options = lspOptions
6869 }
6970
0 commit comments