Web application for exploring and understanding Haskell codebases
Go to file
2018-10-14 18:56:06 +03:00
app WIP. It compiles with ghc-8.4.3, but not all features of the indexer are supported yet. 2018-10-09 23:13:07 +03:00
javascript Generate links to hyperlinked source code on Hackage instead of links to documentation 2018-10-06 01:15:16 +03:00
src/HaskellCodeExplorer Index type constructor in RoleAnnotDecl 2018-10-14 17:15:05 +03:00
test Fix all GHC 8.4.3 compatibility issues. Needs a bit more testing. 2018-10-12 19:45:12 +03:00
vendor/cabal-helper-0.8.1.2 Update cabal-helper to version 0.8.1.2 that supports Cabal (>=1.14 && <1.26 || >=2.0 && <2.5) 2018-10-08 02:40:18 +03:00
.gitignore Initial commit 2018-10-02 13:17:04 +03:00
haskell-code-explorer.cabal Initial commit 2018-10-02 13:17:04 +03:00
LICENSE Initial commit 2018-10-02 13:17:04 +03:00
README.md Add --no-ghc-package-path option to stack exec command in README 2018-10-10 18:30:52 +03:00
Setup.hs Initial commit 2018-10-02 13:17:04 +03:00
stack-8.0.2.yaml Initial commit 2018-10-02 13:17:04 +03:00
stack-8.2.2.yaml WIP. It compiles with ghc-8.4.3, but not all features of the indexer are supported yet. 2018-10-09 23:13:07 +03:00
stack.yaml Fix all GHC 8.4.3 compatibility issues. Needs a bit more testing. 2018-10-12 19:45:12 +03:00

Haskell code explorer

Haskell code explorer is a web application for exploring and understanding Haskell codebases. It provides IDE-like code intelligence features such as types and documentation on hover, "go to definition", "find references" and semantic highlighting.

Examples :

Haskell code explorer

Haskell code explorer consists of an indexer, an HTTP server, and a JavaScript application. The indexer uses GHC API to create a data structure that contains detailed information about the source code of a Cabal package. The HTTP server reads that data structure into memory and responds to HTTP requests from the JavaScript application.

Motivation

Reading and understanding code is an essential part of the software development process. Understanding code in any statically typed language is much easier when code intelligence features (types on hover, go-to-definition, etc.) are available. Code intelligence for Haskell is especially useful because types are informative and precise (thanks to Haskell's purity and global type inference).

Features

  • Types (actual type, instantiated type, instance resolution tree) and documentation on hover. Types are interactive : left-click on type constructor -> go to definition, right click on type constructor -> show kind signature.
    Hover

  • Go to definition

  • Find references

  • Type of each expression
    Expression
    Select a piece of text to get the type of each Haskell expression inside the selection.

  • Semantic highlighting

Installation

git clone https://github.com/alexwl/haskell-code-explorer
cd haskell-code-explorer

To build Haskell code explorer Stack (https://docs.haskellstack.org/en/stable/README/) is needed.

At the moment Haskell code explorer supports GHC 8.2.2 and 8.0.2.

For GHC 8.2.2:

stack install

For GHC 8.0.2:

stack --stack-yaml=stack-8.0.2.yaml install

Indexing source code of a Cabal package

haskell-code-indexer executable is responsible for indexing packages (by default index is saved to .haskell-code-explorer directory).

A package should be built using either cabal-install or stack before indexing (cabal new-build,cabal build, or stack build command should be executed).

haskell-code-indexer requires globally installed GHC and cabal-install (cabal). The reason for this is that haskell-code-indexer uses cabal-helper library https://hackage.haskell.org/package/cabal-helper to get package build information. cabal-helper builds (at runtime) an executable linked against a version of Cabal library that was used to configure the package.

If there is no globally installed GHC on the system, then it is possible to use stack exec command (https://docs.haskellstack.org/en/stable/GUIDE/#exec) that adds a path to GHC binaries installed by Stack to PATH environment variable :

stack --resolver=lts-11.3 exec --no-ghc-package-path haskell-code-indexer -- INDEXER_OPTIONS

Examples :

Show all indexer options:

haskell-code-indexer -h

Index package :

haskell-code-indexer --package PATH

Index package with specific dist directory:

haskell-code-indexer --package PATH --dist dist-newstyle/build/x86_64-linux/ghc-8.2.2/hpath-0.9.2

Index package built by Stack:

haskell-code-indexer --package PATH --dist $(stack path --dist-dir)

Starting HTTP Server

haskell-code-server executable reads the package index created by haskell-code-indexer and starts the HTTP server. The HTTP server responds to API requests and serves static assets (JavaScript files that are in haskell-code-explorer/javascript/release directory).

Examples :

Show all server options :

haskell-code-server -h

Load the indexed package and start the server :

haskell-code-server --package PATH --port 8080 --js-path haskell-code-explorer/javascript/release

Load multiple indexed packages and start the server :

haskell-code-server --package PATH1 --package PATH2 --package PATH3 --port 8080 --js-path haskell-code-explorer/javascript/release

Open http://localhost:8080 in a browser to explore source code of the package.