import Prelude hiding ( id )
import Data.Aeson
+import Control.Exception
import Control.Lens
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import System.IO
+import System.IO.Error
import Language.Haskell.LSP.Types
-import Language.Haskell.LSP.Types.Lens hiding (error)
+import Language.Haskell.LSP.Types.Lens
+ hiding ( error )
import Language.Haskell.LSP.Messages
import qualified Data.HashMap.Strict as HM
getHeaders :: Handle -> IO [(String, String)]
getHeaders h = do
- l <- hGetLine h
+ l <- catch (hGetLine h) eofHandler
let (name, val) = span (/= ':') l
if null val then return [] else ((name, drop 2 val) :) <$> getHeaders h
+ where eofHandler e
+ | isEOFError e = error "Language Server unexpectedly terminated"
+ | otherwise = throw e
type RequestMap = HM.HashMap LspId ClientMethod
let context = SessionContext serverIn absRootDir messageChan reqMap initRsp config caps
initState = SessionState (IdInt 0) mempty mempty 0 False Nothing
-
- threadId <- forkIO $ void $ serverHandler serverOut context
- (result, _) <- runSession context initState session
-
- killThread threadId
+ launchServerHandler = forkIO $ void $ serverHandler serverOut context
+ (result, _) <- bracket launchServerHandler killThread $
+ const $ runSession context initState session
return result
main = hspec $ do
describe "Session" $ do
it "fails a test" $
- -- TODO: Catch the exception in haskell-lsp-test and provide nicer output
+ -- TODO: Catch the exception in lsp-test and provide nicer output
let session = runSession "hie" fullCaps "test/data/renamePass" $ do
openDoc "Desktop/simple.hs" "haskell"
skipMany loggingNotification