Skip to content

Commit 6c0a91c

Browse files
committed
Fix glob edge case
1 parent ebafb8b commit 6c0a91c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ If you use more advanced features, the generated config may not be complete.
5959

6060
- [x] multi component cabal, stack projects
6161
- [x] multiple executables under a single path
62-
- [ ] multiple paths provided to `hs-source-dirs`
62+
- [x] multiple paths provided to `hs-source-dirs`
63+
- [x] lookup nested packages in `cabal.project` or `stack.yaml`
6364
- [ ] common stanzas
6465

6566
### Work, Twitter

src/Hie/Locate.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Control.Monad
1414
import Control.Monad.IO.Class
1515
import Control.Monad.Trans.Maybe
1616
import Data.Attoparsec.Text (parseOnly)
17+
import Data.Either
1718
import Data.List
1819
import Data.Maybe
1920
import qualified Data.Text as T
@@ -23,7 +24,6 @@ import GHC.Generics
2324
import Hie.Cabal.Parser
2425
import Hie.Yaml
2526
import System.Directory
26-
import System.Directory.Internal
2727
import System.FilePath.Posix
2828
import System.FilePattern.Directory (getDirectoryFiles)
2929

@@ -42,12 +42,24 @@ stackYamlPkgs p = liftIO $
4242

4343
cabalPkgs :: FilePath -> MaybeT IO [FilePath]
4444
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
4949
[] -> fail "no cabal files found"
5050
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
5163

5264
nestedPkg :: FilePath -> FilePath -> IO (Maybe Package)
5365
nestedPkg parrent child = do

0 commit comments

Comments
 (0)