From 9fa6772f29efec427269510c8bc85c9d8f8af5b4 Mon Sep 17 00:00:00 2001 From: alexwl Date: Tue, 13 Nov 2018 18:52:47 +0300 Subject: Check for the presence of stack.yaml in the parent directories. Fixes #13. --- src/HaskellCodeExplorer/PackageInfo.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/HaskellCodeExplorer/PackageInfo.hs b/src/HaskellCodeExplorer/PackageInfo.hs index b48ea9b..9be74e2 100644 --- a/src/HaskellCodeExplorer/PackageInfo.hs +++ b/src/HaskellCodeExplorer/PackageInfo.hs @@ -22,7 +22,7 @@ import Control.Exception , try ) import Control.Monad (foldM, join, unless) -import Control.Monad.Extra (findM) +import Control.Monad.Extra (anyM, findM) import Control.Monad.Logger ( LoggingT(..) , MonadLogger(..) @@ -95,8 +95,7 @@ import Outputable (PprStyle, SDoc, neverQualify, showSDocForUser) import Packages (initPackages) import Prelude hiding (id) import System.Directory - ( doesFileExist - , doesFileExist + ( doesFileExist , findExecutable , setCurrentDirectory , getCurrentDirectory @@ -112,7 +111,7 @@ import System.FilePath , splitPath , takeExtension , takeBaseName - , splitDirectories + , splitDirectories ) import System.Process (readProcess) @@ -313,7 +312,12 @@ addReferencesFromModule references modInfo@HCE.ModuleInfo {..} = findDistDirectory :: FilePath -> LoggingT IO FilePath findDistDirectory packagePath = do - hasStackYaml <- liftIO $ doesFileExist (packagePath "stack.yaml") + let parents = + reverse . map joinPath . filter (not . null) . L.inits . splitPath $ + packagePath + -- e.g., ["/dir/subdir/subsubdir","/dir/subdir/","/dir/","/"] + hasStackYaml <- + liftIO $ anyM (\path -> doesFileExist (path "stack.yaml")) parents mbStackExecutable <- liftIO $ findExecutable "stack" let defaultDistDir = packagePath "dist" case (hasStackYaml, mbStackExecutable) of -- cgit v1.2.3