get source code by module name

22 views
Skip to first unread message

Csaba Hruska

unread,
Dec 18, 2017, 4:47:26 PM12/18/17
to haskell-stack
Hi,

I am experimenting with a tool and I need some help or advice.
Assuming a stack based project what is the simplest way to retrieve the source code for a module from the module name?
The module source code should be the same that GHC used when compiled the project.
I'd like to retrieve the source code for both local and stackage modules.

Thanks,
Csaba Hruska

Michael Snoyman

unread,
Dec 19, 2017, 9:57:04 AM12/19/17
to Csaba Hruska, haskell-stack
I can't think of an easy way to do it. It will come down to:

* Looking up which package the module came from (likely in the GHC package database)
* Figuring out if it's in the snapshot or local (the `stack query` command may help here)
* Finding the relevant source code, checking hs-source-dirs in the cabal file, and looking for the file in question

--
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stack+unsubscribe@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-stack/6c05584e-a4c1-463d-bb64-5cbc83ef93e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Burton

unread,
Dec 19, 2017, 1:42:37 PM12/19/17
to Michael Snoyman, Csaba Hruska, haskell-stack
Does Intero not have a feature like this already?

It seems like we have all the info available to at least provide this as a web service for in-snapshot packages. The module-to-package relation is 1 to 1 most of the time.

Michael Sloan

unread,
Jan 15, 2018, 9:53:53 PM1/15/18
to haskell-stack
Hey!

Digging up this thread to mention that I've just merged this PR which has the side effect of making mappings from ModuleName to filepath available in stack's API https://github.com/commercialhaskell/stack/pull/3779/files

-Michael

Csaba Hruska

unread,
Jan 16, 2018, 2:02:50 AM1/16/18
to Michael Sloan, haskell-stack
Excellent!

On Tue, Jan 16, 2018 at 3:29 AM, Michael Sloan <sl...@fpcomplete.com> wrote:
Hey!


I've just merged this PR which has the side effect of making mappings from ModuleName to filepath available in stack's API https://github.com/commercialhaskell/stack/pull/3779/files

-Michael

--
Reply all
Reply to author
Forward
0 new messages