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

Add a new hie-bios cradle component for Setup.hs #6224

Open
ruifengx opened this issue Aug 29, 2023 · 4 comments
Open

Add a new hie-bios cradle component for Setup.hs #6224

ruifengx opened this issue Aug 29, 2023 · 4 comments

Comments

@ruifengx
Copy link

Currently, IDE powered by haskell-language-server cannot load Setup.hs (custom Cabal setup scripts) as it is not listed as a valid target in stack ide targets. Can we add a new <package-name>:setup component for Setup.hs to support this? This component should expose the required compiler options (especially for the dependencies) for building Setup.hs to HLS.

@ruifengx
Copy link
Author

ruifengx commented Aug 29, 2023

By the way, I have a temporary workaround, combining the direct cradle for Setup.hs and the stack cradle for everything else. The problem is that the direct cradle can easily get out of sync with the custom-setup section in package.yaml.

Here is my workaround:

cradle:
  multi:
  - path: ./Setup.hs
    config:
      cradle:
        direct:
          arguments:
          - -package-id=Cabal-3.8.1.0
          - -package-id=base-4.17.1.0
  - path: ./
    config:
      cradle:
        stack:

I did not specify the package-db (as stack would do when building Setup.hs), but it seems to work fine for me (at least for now). It relies on the fact that I have GHC installed and managed globally by GHCup, so there is a ghc executable in PATH, and it happens to be the same one as the one I use for that stack project. Having an official cradle component would definitely solve the problem and make this hack unnecessary.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 3, 2023

@ruifengx, is this, essentially, one aspect of the broader issue #6154? There is no problem with adding a new setup subcommand to stack ide. As stated in that issue, if I am to help myself, I need to understand what is meant by 'all the exact compilation options' or 'the required compiler options'. That is, I do not know what a command stack ide setup would output, and in what format, to be useful to HLS. A simple concrete example would help.

@ruifengx
Copy link
Author

ruifengx commented Sep 3, 2023

Sorry for the lack of context. The compile options for Setup.hs should be the ones that are used to compile it in stack build. As far as I understand, if a custom-setup section is present in package.yaml (and therefore Cabal has build-type: Custom), stack build would work by first compiling Setup.hs (with dependencies listed in the custom-setup section) and the configure and build commands are driven by the compiled setup executable.

To be more specific, by adding a --verbose flag to stack build, I see the compiler options are a bunch of flags for global, snapshot and local package databases, followed by the flags I listed in ghc-options in package.yaml, and finally flags for my default-extensions. Sorry I do not have my laptop at hand, so I cannot attach the actual command line output as a reference. If my description still does not make sense, I can elaborate tomorrow.

About the linked issue, I think my request should in spirit be under the umbrella of that issue, although I did not quite get the details in a hurry (personally, the stack ide command and the stack cradle in hls has usually served me well for Haskell source files in library, executable, and test targets; and when it fails, I could usually work around the problem with a multi-cradle). I do agree that having a compiler options database in JSON etc. would indeed make IDE support more robust.

P.S. more on reproducing this issue itself. If we create a new stack project, add a custom-setup section to enable custom build:

custom-setup:
  dependencies:
  - base
  - Cabal

Load (or reload) this project in VSCode with the Haskell extension enabled, open the Setup.hs file, and we should see a cryptic error message in the bottom right corner (or red squiggles on the first line of that file), which states that hie-bios cannot match any of the components for the opened file (because indeed it is not covered by any of the components listed by stack ide targets), and therefore cannot figure out the required compiler options.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 7, 2023

Related HLS issue: haskell/haskell-language-server#3735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants