@@ -16,31 +16,32 @@ import qualified Distribution.Parsec as Cabal
16
16
import qualified Distribution.Simple.Utils as Cabal
17
17
import qualified Distribution.Utils.Path as Cabal
18
18
import qualified Distribution.Verbosity as Cabal
19
+ import GHC.Data.Maybe (mapMaybe )
19
20
import qualified Language.Haskell.Extension as Language
21
+ import Language.Haskell.Stylish.Config.Internal
20
22
import Language.Haskell.Stylish.Verbose
21
23
import System.Directory (doesFileExist ,
22
24
getCurrentDirectory )
23
25
24
26
25
27
--------------------------------------------------------------------------------
26
- import GHC.Data.Maybe (mapMaybe )
27
- import Language.Haskell.Stylish.Config.Internal
28
-
29
-
30
- --------------------------------------------------------------------------------
31
- findLanguageExtensions :: Verbose -> IO [(Language. KnownExtension , Bool )]
32
- findLanguageExtensions verbose =
33
- findCabalFile verbose >>=
28
+ findLanguageExtensions
29
+ :: Verbose -> ConfigSearchStrategy -> IO [(Language. KnownExtension , Bool )]
30
+ findLanguageExtensions verbose configSearchStrategy =
31
+ findCabalFile verbose configSearchStrategy >>=
34
32
maybe (pure [] ) (readDefaultLanguageExtensions verbose)
35
33
36
34
37
35
--------------------------------------------------------------------------------
38
36
-- | Find the closest .cabal file, possibly going up the directory structure.
39
- -- TODO: use ConfigSearchStrategy here, too
40
- findCabalFile :: Verbose -> IO (Maybe FilePath )
41
- findCabalFile verbose = do
42
- cwd <- getCurrentDirectory
43
- go [] $ ancestors cwd
37
+ findCabalFile :: Verbose -> ConfigSearchStrategy -> IO (Maybe FilePath )
38
+ findCabalFile verbose configSearchStrategy = case configSearchStrategy of
39
+ -- If the invocation pointed us to a specific config file, it doesn't make
40
+ -- much sense to search for cabal files manually (the config file could be
41
+ -- somewhere like /etc, not necessarily a Haskell project).
42
+ UseConfig _ -> pure Nothing
43
+ SearchFromDirectory path -> go [] $ ancestors path
44
+ SearchFromCurrentDirectory -> getCurrentDirectory >>= go [] . ancestors
44
45
where
45
46
go :: [FilePath ] -> [FilePath ] -> IO (Maybe FilePath )
46
47
go searched [] = do
0 commit comments