By | Chris Done |
At | 2011-06-10 |
Title | Display of hlint errors. |
Description |
Edit file amelie.cabal 33188 → 33188
32 32 ,old-locale >= 1.0
33 33 ,safe >= 0.3
34 34 ,hscolour >= 1.17
35 35 ,HJScript >= 0.5
36 36 ,hlint >= 1.8
+ 37 ,filepath >= 1.1
+ 38 ,directory >= 1.0
… … … … Edit file src/Amelie/View/Hlint.hs 33188 → 33188
6 6 7 7 module Amelie.View.Hlint
8 8 (viewHints)
9 9 where
10 10 + 11 import Amelie.View.Html
+ 12 + 13 import Data.List (intersperse)
11 14 import Language.Haskell.HLint
12 15 import Prelude hiding ((++))
13 16 import Text.Blaze.Html5 as H hiding (map)
14 17 15 18 -- | Show hlint hints for a Haskell paste.
16 19 viewHints :: [Suggestion] -> Html
- 17 viewHints _ =
- 18 return ()
+ 20 viewHints = mapM_ showHint where
+ 21 showHint hint =
+ 22 section $ pre $ sequence_ $ intersperse br $ map toHtml lns
+ 23 where section = case suggestionSeverity hint of
+ 24 Ignore -> \_ -> return ()
+ 25 Warning -> warnNoTitleSection
+ 26 Error -> errorNoTitleSection
+ 27 lns = lines $ clean $ show hint
+ 28 clean = dropWhile (==':') . dropWhile (/=':')
… … … … Edit file src/Amelie/View/Html.hs 33188 → 33188
8 8 (aClass
9 9 ,aClasses
10 10 ,darkSection
11 11 ,lightSection
12 12 ,lightNoTitleSection
+ 13 ,warnNoTitleSection
+ 14 ,errorNoTitleSection
13 15 ,href
14 16 ,clear
15 17 ,showLanguage
16 18 ,showChannel)
17 19 where
… … … … 33 35 34 36 -- | A class prefixed with amelie-.
35 37 aClasses :: [Text] -> Attribute
36 38 aClasses names = A.class_ $
37 39 toValue $ T.intercalate " " $ map ("amelie-" ++) names
+ 40 + 41 -- | A warning section.
+ 42 warnNoTitleSection :: Html -> Html
+ 43 warnNoTitleSection inner =
+ 44 H.div ! aClasses ["section","section-warn"] $ do
+ 45 inner
+ 46 + 47 -- | An error section.
+ 48 errorNoTitleSection :: Html -> Html
+ 49 errorNoTitleSection inner =
+ 50 H.div ! aClasses ["section","section-error"] $ do
+ 51 inner
38 52 39 53 -- | A dark section.
40 54 darkSection :: Text -> Html -> Html
41 55 darkSection title inner =
42 56 H.div ! aClasses ["section","section-dark"] $ do
… … … … Edit file src/Amelie/View/Style.hs 33188 → 33188
115 115 borderColor "#EEE"
116 116 color "#000"
117 117 118 118 subRule "h2" $ do
119 119 color "#2D2542"
+ 120 + 121 classRule "section-error" $ do
+ 122 background "#FFDFDF"
+ 123 color "#5b4444"
+ 124 border "1px solid #EFB3B3"
+ 125 + 126 subRule "pre" $ do
+ 127 margin "0"
+ 128 subRule "h2" $ do
+ 129 color "#2D2542"
+ 130 + 131 classRule "section-warn" $ do
+ 132 background "#F1E9D7"
+ 133 color "#915c31"
+ 134 border "1px solid #D3C1B4"
+ 135 subRule "pre" $ do
+ 136 margin "0"
+ 137 subRule "h2" $ do
+ 138 color "#2D2542"
120 139 121 140 -- | Paste view styles.
122 141 paste :: CSS Rule
123 142 paste = do
124 143 classRule "paste-specs" $ do
… … … … Edit file src/Amelie/Controller/Hlint.hs 33188 → 33188
1 1 {-# OPTIONS -Wall -fno-warn-name-shadowing #-}
+ 2 {-# LANGUAGE ScopedTypeVariables #-}
+ 3 {-# LANGUAGE RecordWildCards #-}
+ 4 {-# LANGUAGE ViewPatterns #-}
2 5 3 6 -- | Generate hlint hints.
4 7 5 8 module Amelie.Controller.Hlint
6 9 (getHints)
7 10 where
8 11 9 12 import Amelie.Types
10 13 + 14 import Control.Monad
11 15 import Control.Monad.IO
- 12 import Data.Text (Text,unpack)
+ 16 import Data.Text.IO as T (writeFile)
13 17 import Language.Haskell.HLint
+ 18 import System.Directory
+ 19 import System.FilePath
14 20 15 21 -- | Get hints for a Haskell paste from hlint.
- 16 getHints :: Text -> Controller [Suggestion]
- 17 getHints text = do
- 18 hints <- io $ hlint [unpack text,"--quiet"]
+ 22 getHints :: Paste -> Controller [Suggestion]
+ 23 getHints Paste{pasteId=(fromIntegral -> pid :: Integer),..} = io $ do
+ 24 tmpdir <- getTemporaryDirectory
+ 25 let tmp = tmpdir </> show pid ++ ".hs"
+ 26 exists <- doesFileExist tmp
+ 27 unless exists $ T.writeFile tmp $ pastePaste
+ 28 hints <- hlint [tmp,"--quiet","--ignore=Parse error"]
19 29 return hints
… … … … Edit file src/Amelie/Controller/Paste.hs 33188 → 33188
41 41 html <- cache (Key.Paste pid) $ do
42 42 paste <- model $ getPasteById (fromIntegral pid)
43 43 case paste of
44 44 Nothing -> return Nothing
45 45 Just paste -> do
- 46 hints <- getHints (pastePaste paste)
+ 46 hints <- getHints paste
47 47 pastes <- model $ getAnnotations (fromIntegral pid)
48 48 chans <- model $ getChannels
49 49 langs <- model $ getLanguages
50 50 return $ Just $ page PastePage {
51 51 ppChans = chans
… … … …