Skip to content
Permalink
Browse files

Switch from hindent to ormolu for Haskell-mode autoformat.

  • Loading branch information
cdsmith committed Nov 1, 2019
1 parent 7f24df4 commit fe656e145af9bc77ae0d77dcb7c33af86dac0c83
Showing with 16 additions and 11 deletions.
  1. +2 −1 codeworld-server/codeworld-server.cabal
  2. +13 −9 codeworld-server/src/Main.hs
  3. +1 −1 stack.yaml
@@ -40,10 +40,11 @@ Executable codeworld-server
filelock,
filepath,
haskell-src-exts < 1.21,
hindent >= 5.2.3,
http-conduit,
lifted-base,
memory,
mtl,
ormolu,
process,
regex-compat,
regex-tdfa,
@@ -2,6 +2,8 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC
-fno-warn-incomplete-patterns
-fno-warn-name-shadowing
@@ -41,6 +43,7 @@ import Control.Concurrent (forkIO)
import Control.Concurrent.MSem (MSem)
import qualified Control.Concurrent.MSem as MSem
import Control.Exception (bracket_)
import Control.Exception.Lifted (catch)
import Control.Monad
import Control.Monad.Trans
import Data.Aeson
@@ -57,8 +60,7 @@ import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
import qualified Data.Vector as V
import HIndent (reformat)
import HIndent.Types (defaultConfig)
import Ormolu (ormolu, defaultConfig, OrmoluException)
import Network.HTTP.Simple
import Snap.Core
import Snap.Http.Server (quickHttpServe)
@@ -463,13 +465,15 @@ indentHandler :: CodeWorldHandler
indentHandler = public $ \ctx -> do
mode <- getBuildMode
Just source <- getParam "source"
case reformat defaultConfig Nothing Nothing source of
Left err -> do
modifyResponse $ setResponseCode 500 . setContentType "text/plain"
writeLBS $ LB.fromStrict $ BC.pack err
Right res -> do
modifyResponse $ setContentType "text/x-haskell"
writeLBS $ toLazyByteString res
reformat source `catch` handleError
where
reformat source = do
result <- ormolu defaultConfig "program.hs" (T.unpack (T.decodeUtf8 source))
modifyResponse $ setContentType "text/x-haskell"
writeBS $ T.encodeUtf8 result
handleError (e :: OrmoluException) = do
modifyResponse $ setResponseCode 500 . setContentType "text/plain"
writeLBS $ LB.fromStrict $ BC.pack (show e)

galleryHandler :: CodeWorldHandler
galleryHandler = public $ const $ do
@@ -27,7 +27,7 @@ extra-deps:
- ghc-lib-parser-0.20190909
- haskell-src-exts-1.20.3
- hpc-0.6.0.3
- hindent-5.3.1
- ormolu-0.0.1.0
- kansas-comet-0.4
- monoidal-containers-0.6
- network-2.6.3.6

0 comments on commit fe656e1

Please sign in to comment.
You can’t perform that action at this time.