Skip to content

Commit 684ce68

Browse files
authored
Return warnings from API (#95)
1 parent 989f6be commit 684ce68

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/Main.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ instance A.ToJSON Error
5858

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

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

0 commit comments

Comments
 (0)