diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index 08bff0d..ccd0acf 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -30,7 +30,7 @@ type FileName = String -- or 'GMETooManyCabalFiles' findCabalFiles :: FilePath -> IO (Maybe FilePath) findCabalFiles directory = do - -- Look for cabal files in all parent directories of @dir@ + -- Look for cabal files in @dir@ and all it's parent directories dcs <- getCabalFiles `zipMapM` parents directory -- Extract first non-empty list, which represents a directory with cabal -- files. @@ -42,7 +42,16 @@ findCabalFiles directory = do -- | @getCabalFiles dir@. Find all files ending in @.cabal@ in @dir@. getCabalFiles :: DirPath -> IO [FileName] getCabalFiles dir = - filter ((==) ".cabal" . takeExtension) <$> getDirectoryContents dir + filterM isCabalFile =<< getDirectoryContents dir + where + isCabalFile f = do + exists <- doesFileExist f + return (exists && takeExtension' f == ".cabal") + + takeExtension' p = if takeFileName p == takeExtension p + then "" + else takeExtension p + makeAbsolute :: DirPath -> [FileName] -> [FilePath] makeAbsolute dir fs = (dir ) `map` fs diff --git a/test/PathsAndFilesSpec.hs b/test/PathsAndFilesSpec.hs index aa46f12..aa2a253 100644 --- a/test/PathsAndFilesSpec.hs +++ b/test/PathsAndFilesSpec.hs @@ -8,6 +8,7 @@ import Language.Haskell.GhcMod.GhcPkg #endif import System.Directory +import System.Environment import System.FilePath (()) import Test.Hspec @@ -28,3 +29,7 @@ spec = do it "returns Nothing if the sandbox config file is broken" $ do getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing + + describe "getCabalFiles" $ do + it "doesn't think $HOME/.cabal is a cabal file" $ do + (getCabalFiles =<< getEnv "HOME") `shouldReturn` []