diff --git a/Language/Haskell/GhcMod/CabalHelper.hs b/Language/Haskell/GhcMod/CabalHelper.hs index 119f745..ac11a4b 100644 --- a/Language/Haskell/GhcMod/CabalHelper.hs +++ b/Language/Haskell/GhcMod/CabalHelper.hs @@ -208,7 +208,7 @@ withCabal action = do -- "--flag PACKAGE:[-]FLAG Override flags set in stack.yaml -- (applies to local packages and extra-deps)" - stackReconfigure crdl (optPrograms opts) + stackReconfigure (optStackBuildDeps opts) crdl (optPrograms opts) _ -> error $ "withCabal: unsupported project type: " ++ show proj @@ -234,12 +234,13 @@ withCabal action = do flagOpt = ["--flags", unwords $ map toFlag flgs] liftIO $ void $ readProc (T.cabalProgram progs) ("configure":progOpts) "" - stackReconfigure crdl progs = do + stackReconfigure deps crdl progs = do withDirectory_ (cradleRootDir crdl) $ do supported <- haveStackSupport if supported then do - spawn [T.stackProgram progs, "build", "--only-dependencies", "."] + when deps $ + spawn [T.stackProgram progs, "build", "--only-dependencies", "."] spawn [T.stackProgram progs, "build", "--only-configure", "."] else gmLog GmWarning "" $ strDoc $ "Stack project configuration is out of date, please reconfigure manually using 'stack build' as your stack version is too old (need at least 0.1.4.0)" diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index 7d4aa3a..e648da1 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -146,6 +146,10 @@ globalArgSpec = Options <=> value "UTF-8" <=> showDefault <=> help "I/O encoding" + <*> switch + $$ long "stack-build-deps" + <=> showDefault + <=> help "Build dependencies if needed when using stack" where fileMappingSpec = getFileMapping . splitOn '=' <$> strOption diff --git a/Language/Haskell/GhcMod/Types.hs b/Language/Haskell/GhcMod/Types.hs index f73e01f..2be44cc 100644 --- a/Language/Haskell/GhcMod/Types.hs +++ b/Language/Haskell/GhcMod/Types.hs @@ -106,6 +106,7 @@ data Options = Options { , optGhcUserOptions :: [GHCOption] , optFileMappings :: [(FilePath, Maybe FilePath)] , optEncoding :: String + , optStackBuildDeps :: Bool } deriving (Show) -- | A default 'Options'. @@ -126,6 +127,7 @@ defaultOptions = Options { , optGhcUserOptions = [] , optFileMappings = [] , optEncoding = "UTF-8" + , optStackBuildDeps = False } ----------------------------------------------------------------