@@ -14,6 +14,7 @@ import Control.Monad
14
14
import Control.Monad.IO.Class
15
15
import Control.Monad.Trans.Maybe
16
16
import Data.Attoparsec.Text (parseOnly )
17
+ import Data.Either
17
18
import Data.List
18
19
import Data.Maybe
19
20
import qualified Data.Text as T
@@ -23,7 +24,6 @@ import GHC.Generics
23
24
import Hie.Cabal.Parser
24
25
import Hie.Yaml
25
26
import System.Directory
26
- import System.Directory.Internal
27
27
import System.FilePath.Posix
28
28
import System.FilePattern.Directory (getDirectoryFiles )
29
29
@@ -42,12 +42,24 @@ stackYamlPkgs p = liftIO $
42
42
43
43
cabalPkgs :: FilePath -> MaybeT IO [FilePath ]
44
44
cabalPkgs p = do
45
- cp <- liftIO (try $ T. readFile $ p </> " cabal.project" :: IO ( Either IOException T. Text ))
46
- case parseOnly extractPkgs <$> cp of
47
- Right ( Right f) -> liftIO $ map (p </> ) <$> getDirectoryFiles p ( map T. unpack f)
48
- _ -> filter (( " .cabal " == ) . takeExtension) <$> liftIO (listDirectory p) >>= \ case
45
+ cp <- cabalP " cabal.project"
46
+ cl <- cabalP " cabal.project.local "
47
+ case concat . rights $ map (parseOnly extractPkgs) $ rights [cp, cl] of
48
+ [] -> liftIO (cfs p) >>= \ case
49
49
[] -> fail " no cabal files found"
50
50
h : _ -> pure [p </> h]
51
+ xs -> do
52
+ cd <- liftIO $ map (p </> ) <$> getDirectoryFiles p (map (matchDirs . T. unpack) xs)
53
+ cf <-
54
+ liftIO $
55
+ mapM (\ p -> if takeExtension p == " .cabal" then pure [p] else cfs p) cd
56
+ pure $ concat cf
57
+ where
58
+ cabalP n = liftIO (try $ T. readFile $ p </> n :: IO (Either IOException T. Text ))
59
+ cfs d = filter ((" .cabal" == ) . takeExtension) <$> listDirectory d
60
+ matchDirs p | " /" `isSuffixOf` p = p <> " *.cabal"
61
+ matchDirs p | " *" `isSuffixOf` p || takeExtension p == " " = p <> " /*.cabal"
62
+ matchDirs p = p
51
63
52
64
nestedPkg :: FilePath -> FilePath -> IO (Maybe Package )
53
65
nestedPkg parrent child = do
0 commit comments