Using the GHC API: pretty printing with qualified names

scooter.phd at gmail.com scooter.phd at gmail.com
Wed Nov 17 23:12:43 EST 2010


Claus:

scion-server mimics a GHCi command line, of sorts. scion-server is used very successfully to syntax-highlight the Eclipse editor, show a source's outline, provide type information when hovering over a name, and provide completions.

That's not the problem, per se. Let's say I'm hovering over a function that's imported by Data.Map. When resolved, the symbols appear to come from Ghc.Map (if memory serves correctly), which makes finding the correct "haddock" impossible.


-scooter


Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: "Claus Reinke" <claus.reinke at talk21.com>
Sender: glasgow-haskell-users-bounces at haskell.org
Date: Wed, 17 Nov 2010 23:25:29 
To: JP Moresmau<jpmoresmau at gmail.com>; <glasgow-haskell-users at haskell.org>
Subject: Re: Using the GHC API: pretty printing with qualified names

> Hello, I'm the maintainer for EclipseFP, which involves using the scion
> library and the GHC API to provide IDE functionality. I have a little 
> issue
> that no doubt stems from me not understanding the GHC API well, and I 
> would
> be grateful for any light on the matter.

A meta-comment: the GHC API is much easier to grasp if
you have a client at hand. In the case of IDE-like tools, my
recommendation would be to look at the GHCi source -
there is a wide range of overlap between what makes
sense for GHCi and what makes sense for an IDE (think
of GHCi as a commandline IDE;-).

For your particular question: GHCi provides :info, which
does manage to get (rough) source info for plain unqualified
names, within a session context. So, starting from the source
of the :info implementation might give you some hints (the
command itself also helps you to find the GHC API source
in question).

Prelude> :set -package ghc
Prelude> :info GHC.getName
class Name.NamedThing a where
  ...
  Name.getName :: a -> Name.Name
        -- Defined in Name

Prelude> :info Monad
class Monad m where
  (>>=) :: m a -> (a -> m b) -> m b
  (>>) :: m a -> m b -> m b
  return :: a -> m a
  fail :: String -> m a
        -- Defined in GHC.Base
instance Monad Maybe -- Defined in Data.Maybe
instance Monad [] -- Defined in GHC.Base
instance Monad IO -- Defined in GHC.Base

Prelude> :info mapM
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
        -- Defined in Control.Monad

Of course, those sources and GHCi commands aren't
perfect (some of the code might still pre-date the API),
and batch-processing an AST is different from an
interactive read-eval-print loop, but some of the API
was abstracted from GHCi and GHCi always needs to
build with the current API version.

Another side note: as you can see from the examples,
you may not always have any source code to point to,
in a typical GHC installation. That is why haskellmode
for Vim links to the haddocks for those ids (somewhat
oddly, the haddocks might come with HTML-ified sources,
even when the original source is not installed..).

Hope this helps,
Claus
 

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users at haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list