Avi-D-coder / implicit-hie

Auto generate a stack or cabal multi component hie.yaml file
BSD 3-Clause "New" or "Revised" License
201 stars 17 forks source link

Support both --stack and --cabal at the same time #46

Closed chshersh closed 2 years ago

chshersh commented 2 years ago

I'm currently in a situation where a project is developed by a team. Some people use stack and others cabal. We use gen-hie as a pre-commit hook, so it would be nice if it can support both --cabal and --stack options to generate two cradles at the same time.

Taking the example from the README, the output would be something like this:


$ gen-hie --cabal --stack
cradle:
  cabal:
    - path: "indexed-profunctors/src"
      component: "lib:indexed-profunctors"

    - path: "optics-th/src"
      component: "lib:optics-th"

    - path: "optics-th/tests"
      component: "optics-th:test:optics-th-tests"

    - path: "optics-vl/src"
      component: "lib:optics-vl"

    - path: "codegen/./Subtypes.hs"
      component: "optics-codegen:exe:optics-codegen-subtypes"

    - path: "optics-core/src"
      component: "lib:optics-core"

    - path: "optics-sop/src"
      component: "lib:optics-sop"

    - path: "optics-extra/src"
      component: "lib:optics-extra"

    - path: "template-haskell-optics/src"
      component: "lib:template-haskell-optics"

    - path: "optics/src"
      component: "lib:optics"

    - path: "optics/tests"
      component: "optics:test:optics-tests"

    - path: "metametapost/src/Cli.hs"
      component: "metametapost:exe:metametapost-optics"

  stack:
    - path: "indexed-profunctors/src"
      component: "indexed-profunctors:lib"

    - path: "optics-th/src"
      component: "optics-th:lib"

    - path: "optics-th/tests"
      component: "optics-th:test:optics-th-tests"

    - path: "optics-vl/src"
      component: "optics-vl:lib"

    - path: "codegen/./Subtypes.hs"
      component: "optics-codegen:exe:optics-codegen-subtypes"

    - path: "optics-core/src"
      component: "optics-core:lib"

    - path: "optics-sop/src"
      component: "optics-sop:lib"

    - path: "optics-extra/src"
      component: "optics-extra:lib"

    - path: "template-haskell-optics/src"
      component: "template-haskell-optics:lib"

    - path: "optics/src"
      component: "optics:lib"

    - path: "optics/tests"
      component: "optics:test:optics-tests"

    - path: "metametapost/src/Cli.hs"
      component: "metametapost:exe:metametapost-optics"
fendor commented 2 years ago

Hi!

For my understanding, you do know that such a hie.yaml would be invalid? Is such a feature still useful in that case?

As another side-info, the simple cabal cradle:

cradle:
  cabal:

will work presumably for cabal projects (assuming cabal >= 3.4).

chshersh commented 2 years ago

@fendor I didn't know that such a hie.yaml would be invalid 😮 I haven't found any documentation on this. Maybe you can point me to it if I missed it or maybe documentation can be improved?

At least it such a stack+cabal configj worked with my Cabal build but maybe it doesn't work with Stack. Or maybe something different happened.

It's a pity it's not supported. Unfortunately, having only cabal cradle isn't an option for me. So this issue can be closed if such a hie.yaml config is indeed invalid.

fendor commented 2 years ago

The only documentation we have is here: https://github.com/haskell/hie-bios Essentially, the hie.yaml documents how you load a project into your IDE, it allows you to specify which tool you want to use, cabal or stack, having both does not make sense in its current interpretation. Then the IDE would still not know what you want to use.

Maybe it is some oddity of the yaml parser... But it will only use one of the two.

It is definitely invalid currently.

chshersh commented 2 years ago

@fendor Thanks for the confirmation! I was refering to the "config" section of the HLS documentation:

Specifically, when the text says:

"The complete configuration is a subset of

cradle:
  cabal:
    component: "optional component name"
  stack:
    component: "optional component name"
  bios:
    program: "program to run"
    dependency-program: "optional program to run"
  direct:
    arguments: ["list","of","ghc","arguments"]
  default:
  none:

dependencies:
  - someDep

"

So, I assumed that "subset" means any combination of cradles from this example. I haven't found anywhere a mention that only one cradle is supported at the time so I simply assumed it would work.

Then the IDE would still not know what you want to use.

I can imagine that IDE can use the one it finds in PATH. If it finds both, it can use any (doesn't really matter for me). But this is a different logic and probably not worth complicated the IDE setup.

I'm closing this issue since the requested feature is not supported by hie-bios in the first place.