Skip to content

Return warnings from API #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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