runCommand (CmdType real file (line, col)) = do
    let status = respond . ClientLog "Type"
    setCurrentFile real file
    status "Get type"
    result <- withWarnings False $
        getType file (line, col)
    status "Check result"
    case result of
        Left err -> do
          respond $ ClientStderr err
          return $ ExitFailure 1
        Right types -> do
            mapM_ (respond . ClientStdout . formatType) types
            return ExitSuccess
    where
    formatType :: ((Int, Int, Int, Int), String) -> String
    formatType ((startLine, startCol, endLine, endCol), t) =
        concat
            [ show startLine , " "
            , show startCol , " "
            , show endLine , " "
            , show endCol , " "
            , "\"", t, "\""
            ]
runCommand (CmdType real file (line, col)) = do
    let status = respond . ClientLog "Type"
    setCurrentFile real file
    status "Get type"
    result <- withWarnings False $
        getType file (line, col)
    status "Check result"
    case result of
        Left err -> do
          respond $ ClientStderr err
          return $ ExitFailure 1
        Right types -> do
            mapM_ (respond . ClientStdout . formatType) types
            return ExitSuccess
    where
    formatType :: ((Int, Int, Int, Int), String) -> String
    formatType ((startLine, startCol, endLine, endCol), t) =
        concat
            [ show startLine , " "
            , show startCol , " "
            , show endLine , " "
            , show endCol , " "
            , "\"", t, "\""
            ]
runCommand (CmdType real file (line, col)) = do
    let status = respond . ClientLog "Type"
    setCurrentFile real file
    status "Get type"
    result <- withWarnings False $
        getType file (line, col)
    status "Check result"
    case result of
        Left err -> do
          respond $ ClientStderr err
          return $ ExitFailure 1
        Right types -> do
            mapM_ (respond . ClientStdout . formatType) types
            return ExitSuccess
    where
    formatType :: ((Int, Int, Int, Int), String) -> String
    formatType ((startLine, startCol, endLine, endCol), t) =
        concat
            [ show startLine , " "
            , show startCol , " "
            , show endLine , " "
            , show endCol , " "
            , "\"", t, "\""
            ]