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

How to extract flags used to make GHCi session? #363

Closed
mpickering opened this issue Feb 27, 2019 · 8 comments
Closed

How to extract flags used to make GHCi session? #363

mpickering opened this issue Feb 27, 2019 · 8 comments
Labels
Low Severity question User has a query

Comments

@mpickering
Copy link

mpickering commented Feb 27, 2019

I want to add support to haskell-ide-engine for obelisk.

In order to do this I just need the list of flags used to invoke ghci when ob run is called.

My ideal interface is that there is a command I can run (for example ob get-args common/Foo.hs) which will output the list of flags such that ghci $(ob get-args common/Foo.hs) common/Foo.hs will succeed.

I haven't yet looked into the internals of obelisk so a little bit of direction might be all I need to implement this. I've already implemented support for cabal, hadrian and rules_haskell.

@eskimor
Copy link
Collaborator

eskimor commented Feb 27, 2019

runGhcid uses:

      , "--command='ghci -Wall -ignore-dot-ghci -fwarn-redundant-constraints -no-user-package-db -ghci-script " <> dotGhci <> "' "

The interesting part will be the dotGhci, which gets provided by withGhciScript, which passes in extensions from cabal, needed packages and such.

I don't think that this information is exposed right now, but it should not be hard to provide a command which exposes the needed information.

@eskimor
Copy link
Collaborator

eskimor commented Feb 27, 2019

Alternatively, "just" linking with obelisk-command would give you access to that function. Don't know if this is an option.

@mpickering
Copy link
Author

Thanks for your prompt reply @eskimor

Right, linking is not an option. withGhcCmd looks like what I need but it seems that some arguments that should appear on the command line are in the script.

Would it be appropriate to refactor withGhciScript so that the continuation is of type ([String], FilePath) -> m () so that the first component of the tuple is the command line arguments and the second is the .ghci file? That way I could easily implement a target which dumped out the necessary command line.

I was also wondering that there is no call to -package-db, where is the package database? Perhaps there is something funny going on with -i in the script.

@3noch
Copy link
Collaborator

3noch commented Feb 28, 2019

The package db is generated by nix in a nix-shell ultimately via ghcWithPackages.

@benkolera
Copy link
Contributor

@mpickering The way that I go about this is to wrap up the commands that are being run in a nix-shell.

In my current emacs setup, that actually means running hie in a nix shell, running a separate hie for backend/common/frontend. Like so:

nix-shell -I . --arg hie true --command hie-wrapper --lsp -d -l /tmp/hie.log /home/bkolera/src/github/qfpl/reflex-realworld-example/frontend . This is done by having a shell.nix next to the cabal file that is import (../.).shells.ghc to get the right haskell environment in the shell.

This way, hie just runs individually for each cabal file, but it's not entirely idea. I end up having to create a sandbox for each cabal file and add-sourcing common so that they play nice. It's not ideal and can get pretty flakey with the slower than normal compile times in obelisk land, but my setup may help you a little (or at least not hurt), perhaps! 🙂

@mpickering
Copy link
Author

Thanks @benkolera

I implemented prototype support for this on my branch - https://github.com/mpickering/obelisk/tree/ide-args

It worked with the example project you linked above (after launching vscode from the shell). There is a problem with TemplateHaskell and jsaddle-dom seeming to hang whilst loading. I don't have time to investigate that now but support for obelisk should definitely be possible in future once we work that out. It is probably just setting some options incorrectly.

@3noch
Copy link
Collaborator

3noch commented Apr 1, 2019

Note that we can get the pkg database directly:

cat "$(nix-build -E '(import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [p.vector])' --no-out-link)"/bin/ghci
#! /nix/store/cinw572b38aln37glr0zb8lxwrgaffl4-bash-4.4-p23/bin/bash -e
export NIX_GHC='/nix/store/i512zr3700xrc9d6aapjwqa1hxgj53kl-ghc-8.6.4-with-packages/bin/ghc'
export NIX_GHCPKG='/nix/store/i512zr3700xrc9d6aapjwqa1hxgj53kl-ghc-8.6.4-with-packages/bin/ghc-pkg'
export NIX_GHC_DOCDIR='/nix/store/i512zr3700xrc9d6aapjwqa1hxgj53kl-ghc-8.6.4-with-packages/share/doc/ghc/html'
export NIX_GHC_LIBDIR='/nix/store/i512zr3700xrc9d6aapjwqa1hxgj53kl-ghc-8.6.4-with-packages/lib/ghc-8.6.4'
exec "/nix/store/8vq01xmxlp9wxzilkw85rb621ag7nwmd-ghc-8.6.4/bin/ghci"  "-B$NIX_GHC_LIBDIR" "${extraFlagsArray[@]}" "$@"

@madeline-os
Copy link
Collaborator

I'm closing this as the motivating use-case, haskell-ide-engine, has been supplanted by HLS. HLS integration is on our roadmap. Anyone that still has a use-case is welcome to make another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Low Severity question User has a query
Projects
None yet
Development

No branches or pull requests

7 participants