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

stack ghci doesn't load any files #355

Closed
ndmitchell opened this issue Jun 19, 2015 · 18 comments
Closed

stack ghci doesn't load any files #355

ndmitchell opened this issue Jun 19, 2015 · 18 comments

Comments

@ndmitchell
Copy link
Contributor

C:\Neil\hlint>stack --version
Version 0.0.3.1, Git revision e3b18221509a7609b9ab6124ced5294dec05c82a

C:\Neil\hlint>stack ghci
Configuring GHCi with the following packages: hlint
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :show modules
Prelude>

I was expecting stack ghci to load the hlint library, but it doesn't, it loads nothing.

@ndmitchell
Copy link
Contributor Author

btw, this is after deleting the .ghci file in the hlint repo, to replicate the "normal user" experience.

@chrisdone
Copy link
Member

Related: #347 (comment)

tl;dr it's not supposed to load anything on start-up, but enough people want it that I'll make it do that by default and add --no-load flag for people like me who don't want it doing that by default.

@ndmitchell
Copy link
Contributor Author

I don't super care about the default, since this is for using it through ghcid, but is there any way to replicate something close to what cabal repl does?

Also:

C:\Neil\hlint>stack ghci Sample.hs
Configuring GHCi with the following packages:
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude>

I would have expected that to try loading Sample.hs.

@chrisdone
Copy link
Member

This works: #328 (comment)

chris@retina:~/Work/stack$ stack ghci --ghc-options X.hs
Configuring GHCi with the following projects: stack
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Warning: -debug, -threaded and -ticky are ignored by GHCi
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> 

But enough people have assumed stack ghci should run :load automatically on all target modules by default that it's planned for implementation.

@ndmitchell
Copy link
Contributor Author

OK, I guess I'll hold off on integration until after things have settled down.

@ndmitchell
Copy link
Contributor Author

@chrisdone - can you please update this ticket once you think stack is ready and isn't going to change significantly.

@chrisdone
Copy link
Member

Sure.

@snoyberg snoyberg added this to the 0.2.0.0 milestone Jun 21, 2015
@snoyberg snoyberg modified the milestones: 0.2.0.0, GHCi Jul 13, 2015
@ndmitchell
Copy link
Contributor Author

So currently for https://github.com/ndmitchell/hoogle stack ghci is loading all the "other-modules" in the executable, but not "Main". That seems a bit weird. Is that a known issue?

@chrisdone
Copy link
Member

Yeah, as Main is ambiguous in the presence executables and test suites. But with the new target code one will be able to specify which targets to load to clarify this ambiguity.

@ndmitchell
Copy link
Contributor Author

Is the first executable or test-suite in the module not a good default? That way people could reorder their cabal file to get what they are after.

@ndmitchell
Copy link
Contributor Author

I should also note that I always name my executables and test suites differently and us -main-is, precisely so I can load them all simultaneously (and because that's how some other proprietary Haskell variants work, and seems much more sensible).

@chrisdone
Copy link
Member

I imagine -main-is takes a filename? So it would be like stack ghci --main-is src/main/Main.hs to automatically load that module on start-up.

We could have it take a cabal component name instead in the interest of being convenient, e.g. -main-is exe:foo or -main-is test:foo.

@ndmitchell
Copy link
Contributor Author

Yep, search for main-is here: https://github.com/ndmitchell/shake/blob/master/shake.cabal

@chrisdone
Copy link
Member

What if you have a test suite named Main and an executable named Main? How would you want to distinguish them when calling stack ghci?

@ndmitchell
Copy link
Contributor Author

I would have thought:

  • Always load as many modules as you can while they don't overlap. e.g. If there is one Test and one Main, try loading both at once.
  • The prompt should have active (e.g. imported into it) the first "thing" loaded, either a test suite or an executable, whatever is first in the .cabal file. If there are no test suites or executables, import all modules exposed.
  • Let people pass the name of a test-suite or executable to refine the choice, e.g. for shake the executable is executable shake and the test suite is test-suite shake-test.

@chrisdone
Copy link
Member

I've implemented this. If I load up stack ghci in lucid, I get:

The main module to load is ambiguous. Candidates are: 
Package `lucid' component test:test with main-is file: /home/chris/Packages/lucid/test/Main.hs
Package `lucid' component bench:bench with main-is file: /home/chris/Packages/lucid/benchmarks/Main.hs
None will be loaded. You can specify which one to pick by: 
 1) Specifying targets to stack ghci e.g. stack ghci lucid:test:test
 2) Specifying what the main is e.g. stack ghci --main-is lucid:test:test

So I can either just load the one target that I want, or I can proceed trying to load everything and specify what the main is.

@ndmitchell
Copy link
Contributor Author

Awesome! Just tried this with HLint and it worked straight away.

@chrisdone
Copy link
Member

Cool, closing.

@borsboom borsboom modified the milestone: GHCi Sep 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants