jonascarpay / calligraphy

haskell source code visualizer
BSD 3-Clause "New" or "Revised" License
97 stars 13 forks source link

Option to show just the module graph #5

Closed jonascarpay closed 2 years ago

jonascarpay commented 2 years ago

Fixes #4

This is an initial stab at allowing just a high-level overview of the module graph with --collapse-modules.

calligraphy 'src/*' -p out.png --collapse-modules

out

I thought it would be nice to hide the entire functionality behind a single flag, but now that I've written it, I think I might prefer https://github.com/jonascarpay/calligraphy/issues/4#issuecomment-1110617467. It requires more flags to get the same result as the above graph, but it would be more flexible, and integrates nicely and predictably with the existing logic.

One other possible design:

I'm not sure if dissolving would ever be useful outside of modules, though. If not, it's just a roundabout way of achieving https://github.com/jonascarpay/calligraphy/issues/4#issuecomment-1110617467

jonascarpay commented 2 years ago

Unfortunately, HIE files (GHC?) can't tell you whether a module is hidden or exposed. Having dashed outlines for hidden modules would've been neat.

jonascarpay commented 2 years ago

Now that I think about it, dissolving could just be a hiding mode. That way, --collapse-modules would automatically just override the default behavior of --dissolve-modules, and we'd be good! I'm taking a stab at this later today, it would probably coincide with a much-needed cleanup of the Parse module. It's old, and full of scars.

jonascarpay commented 2 years ago

I ended up adding it as a special case to the Collapse phase (8ae6aa557e97431bb8beb50bdbf44cc0fd70b6e9), which is now called the NodeFilter phase (12ecd1c409fb23b5c47de71f28ad1c3ff6b52005).

I initially implemented --collapse-modules as described in https://github.com/jonascarpay/calligraphy/pull/5#issue-1216940797 and https://github.com/jonascarpay/calligraphy/pull/5#issuecomment-1110726279, but it turns out that having a top-level node for modules just isn't very useful in contexts other than collapsing modules. Besides, it was arguably hackier that the current implementation, because the module node doesn't actually correspond to any actual declaration. To the degree that it's a kludge now, it's at least a) honest about that b) easy to change should anyone get a better idea and c) at a point in the pipeline where we don't break the abstraction for literally the entire downstream.

out