Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit cradle upper-directory priorities #212

Open
lukel97 opened this issue Jun 25, 2020 · 2 comments
Open

Implicit cradle upper-directory priorities #212

lukel97 opened this issue Jun 25, 2020 · 2 comments
Labels
type: enhancement New feature or request

Comments

@lukel97
Copy link
Contributor

lukel97 commented Jun 25, 2020

This is open to discussion, not really a bug as much as potentially surprising behaviour. Consider the following directory structure:

.
├── cabal
│   ├── A.hs
│   └── cabal.project
├── stack
│   ├── B.hs
│   └── stack.yaml
└── stack.yaml

Inside the cabal and stack folders, there's an ambiguity as to what directory it should pick for the cradle: it can either choose the more local nested one or the stack.yaml in the upper directory.
In the cabal folder:

$ hie-bios cradle cabal/A.hs 
Cradle for "/Users/luke/Desktop/stack-cabal-mix/cabal/A.hs": Cradle {cradleRootDir = "/Users/luke/Desktop/stack-cabal-mix", cradleOptsProg = CradleAction: Stack}

That seems fair enough, it's choosing the more global stack project.
But in the stack folder:

$ hie-bios cradle stack/B.hs
Cradle for "/Users/luke/Desktop/stack-cabal-mix/stack/B.hs": Cradle {cradleRootDir = "/Users/luke/Desktop/stack-cabal-mix/stack", cradleOptsProg = CradleAction: Stack}

It chooses the more local folder!
This isn't a bug but rather just how the implicit cradle search is done:

implicitConfig' :: FilePath -> MaybeT IO (CradleType a, FilePath)
implicitConfig' fp = (\wdir ->
         (Bios (Program $ wdir </> ".hie-bios") Nothing, wdir)) <$> biosWorkDir fp
  --   <|> (Obelisk,) <$> obeliskWorkDir fp
  --   <|> (Bazel,) <$> rulesHaskellWorkDir fp
     <|> (stackExecutable >> (Stack Nothing,) <$> stackWorkDir fp)
     <|> ((Cabal Nothing,) <$> cabalWorkDir fp)


stackWorkDir :: FilePath -> MaybeT IO FilePath
stackWorkDir = findFileUpwards isStack
  where
    isStack name = name == "stack.yaml"

This means that stack will always win over cabal if it can find a stack.yaml in any upwards directory.
What I would have expected would be for both cabal.project and stack.yaml to be searched for in the current directory, before peeking in the parent directories. Thoughts?

@fendor
Copy link
Collaborator

fendor commented Jun 25, 2020

I agree, that would be the better behaviour.

@fendor fendor added the type: enhancement New feature or request label Jul 3, 2020
@fendor
Copy link
Collaborator

fendor commented Jul 12, 2020

This was implemented via #221

EDIT:
Actually that specific behaviour hasn't been changed

@fendor fendor closed this as completed Jul 12, 2020
@fendor fendor reopened this Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants