Skip to content

Commit

Permalink
Return warnings from API (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 authored Sep 1, 2017
1 parent 989f6be commit 684ce68
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ instance A.ToJSON Error

server :: TL.Text -> [P.ExternsFile] -> P.Environment -> Int -> IO ()
server bundled externs initEnv port = do
let compile :: Text -> IO (Either Error JS)
let compile :: Text -> IO (Either Error ([P.JSONError], JS))
compile input
| T.length input > 20000 = return (Left (OtherError "Please limit your input to 20000 characters"))
| otherwise = do
Expand All @@ -67,7 +67,7 @@ server bundled externs initEnv port = do
Left parseError ->
return . Left . CompilerErrors . pure . P.toJSONError False P.Error . P.toPositionedError $ parseError
Right (_, m) | P.getModuleName m == P.ModuleName [P.ProperName "Main"] -> do
(resultMay, _) <- runLogger' . runExceptT . flip runReaderT P.defaultOptions $ do
(resultMay, ws) <- runLogger' . runExceptT . flip runReaderT P.defaultOptions $ do
((P.Module ss coms moduleName elaborated exps, env), nextVar) <- P.runSupplyT 0 $ do
[desugared] <- P.desugar externs [P.importPrim m]
P.runCheck' (P.emptyCheckState initEnv) $ P.typeCheckModule desugared
Expand All @@ -79,7 +79,7 @@ server bundled externs initEnv port = do
P.evalSupplyT nextVar $ P.prettyPrintJS <$> J.moduleToJs renamed Nothing
case resultMay of
Left errs -> (return . Left . CompilerErrors . P.toJSONErrors False P.Error) errs
Right js -> (return . Right) js
Right js -> (return . Right) (P.toJSONErrors False P.Error ws, js)
Right _ -> (return . Left. OtherError) "The name of the main module should be Main."

scotty port $ do
Expand All @@ -96,8 +96,8 @@ server bundled externs initEnv port = do
case response of
Left err ->
Scotty.json $ A.object [ "error" .= err ]
Right comp ->
Scotty.json $ A.object [ "js" .= comp ]
Right (warnings, comp) ->
Scotty.json $ A.object [ "js" .= comp, "warnings" .= warnings ]
get "/search" $ do
query <- param "q"
Scotty.setHeader "Access-Control-Allow-Origin" "*"
Expand Down

0 comments on commit 684ce68

Please sign in to comment.