File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ cabal-version: 1.12
4
4
--
5
5
-- see: https://github.com/sol/hpack
6
6
--
7
- -- hash: 62b7d90b1ed53933a4c7c61b6392cf2f7ce368607095d9255b80154c6997e755
7
+ -- hash: 18f92037a7863d121ac45e847f7dc6177adf0ebc7951dfa1588340f86e64456b
8
8
9
9
name : implicit-hie
10
10
version : 0.1.0.0
@@ -40,7 +40,9 @@ library
40
40
, base >= 4.7 && < 5
41
41
, directory
42
42
, filepath
43
+ , filepattern
43
44
, text
45
+ , transformers
44
46
, yaml
45
47
default-language : Haskell2010
46
48
@@ -56,8 +58,10 @@ executable gen-hie
56
58
, base >= 4.7 && < 5
57
59
, directory
58
60
, filepath
61
+ , filepattern
59
62
, implicit-hie
60
63
, text
64
+ , transformers
61
65
, yaml
62
66
default-language : Haskell2010
63
67
@@ -74,9 +78,11 @@ test-suite implicit-hie-test
74
78
, base >= 4.7 && < 5
75
79
, directory
76
80
, filepath
81
+ , filepattern
77
82
, hspec
78
83
, hspec-attoparsec
79
84
, implicit-hie
80
85
, text
86
+ , transformers
81
87
, yaml
82
88
default-language : Haskell2010
Original file line number Diff line number Diff line change @@ -22,9 +22,11 @@ description: "Auto generate a stack or cabal multi component hie.yaml file"
22
22
dependencies :
23
23
- base >= 4.7 && < 5
24
24
- text
25
+ - transformers
25
26
- attoparsec
26
27
- yaml
27
28
- directory
29
+ - filepattern
28
30
- filepath
29
31
30
32
ghc-options :
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Control.Applicative
6
6
import Control.Monad
7
7
import Data.Attoparsec.Text
8
8
import Data.Char
9
+ import Data.Maybe
9
10
import Data.Text (Text )
10
11
import qualified Data.Text as T
11
12
@@ -86,7 +87,7 @@ parseString :: Parser Name
86
87
parseString = parseQuoted <|> unqualName
87
88
88
89
unqualName :: Parser Text
89
- unqualName = takeWhile1 (\ c -> isAlphaNum c || c `elem` ( " -_./ " :: String ))
90
+ unqualName = takeWhile1 (not . ( \ c -> isSpace c || c == ' , ' ))
90
91
91
92
parseList :: Indent -> Parser [Text ]
92
93
parseList i = items <|> (emptyOrComLine >> indent i >> items)
@@ -166,3 +167,6 @@ indent :: Indent -> Parser Int
166
167
indent i = do
167
168
c <- length <$> many' tabOrSpace
168
169
if c >= i then pure c else fail " insufficient indent"
170
+
171
+ extractPkgs :: Parser [T. Text ]
172
+ extractPkgs = join . catMaybes <$> many' (Just <$> field 0 " packages" parseList <|> (skipToNextLine >> pure Nothing ))
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE LambdaCase #-}
2
+ {-# LANGUAGE OverloadedStrings #-}
3
+
1
4
module Hie.Locate
2
5
( nestedPkg ,
3
6
nestedCabalFiles ,
7
+ stackYamlPkgs ,
8
+ cabalProjectPkgs ,
4
9
)
5
10
where
6
11
12
+ import Control.Applicative
7
13
import Control.Monad
14
+ import Control.Monad.IO.Class
15
+ import Control.Monad.Trans.Maybe
8
16
import Data.Attoparsec.Text
9
17
import Data.List
10
18
import Data.Maybe
11
19
import qualified Data.Text as T
12
20
import qualified Data.Text.IO as T
21
+ import Data.Yaml
22
+ import GHC.Generics
13
23
import Hie.Cabal.Parser
14
24
import Hie.Yaml
15
25
import System.Directory
16
26
import System.Directory.Internal
17
27
import System.FilePath.Posix
18
28
29
+ newtype Pkgs = Pkgs [FilePath ]
30
+ deriving (Eq , Ord )
31
+
32
+ instance FromJSON Pkgs where
33
+ parseJSON (Object v) = Pkgs <$> v .: " packages"
34
+ parseJSON _ = fail " could not read packages from stack.yaml"
35
+
36
+ stackYamlPkgs :: FilePath -> MaybeT IO [FilePath ]
37
+ stackYamlPkgs p = liftIO $
38
+ decodeFileEither (p </> " stack.yaml" ) >>= \ case
39
+ Right (Pkgs f) -> pure f
40
+ Left e -> fail $ show e
41
+
42
+ cabalProjectPkgs :: FilePath -> MaybeT IO [FilePath ]
43
+ cabalProjectPkgs p = do
44
+ cp <- liftIO $ T. readFile $ p </> " cabal.project"
45
+ case parseOnly extractPkgs cp of
46
+ Right f -> pure $ map T. unpack f
47
+ _ -> fail " No packages found"
48
+
19
49
nestedCabalFiles :: FilePath -> IO [FilePath ]
20
50
nestedCabalFiles f = do
21
51
fs <- listDirectory f
You can’t perform that action at this time.
0 commit comments