When I was learning Haskell, I was missing the nice features of IntelliJ IDEA. First approach was to use default way of creating IntelliJ plugin by defining grammar and lexer according to Haskell report. That did not workout because I could not define all the recursiveness. Decided to use grammar and lexer definitions only for tokenizing and parsing Haskell code, so not for syntax checking the code. This is needed for syntax highlighting, all kind of navigation and so on. Further Haskell language support is done with the support of the external tools: ghc-mod and haskell-docs.
This plugin is written mainly in Scala and is not mentioned to support GHC/Cabal directly. This plugin support sandbox projects and expects that the Cabal init/install/build is done on command-line.
Any feedback is welcome!!
- Syntax highlighting (which can be customized);
- Error/warning highlighting;
- Find Usages of identifiers;
- Resolving references of identifiers (also to library code if library source code is added to project and resolves inside import declaration);
- Code completion by resolving references;
- Inplace rename identifiers (in which global rename first shows preview so refactoring scope can be adjusted).
- View type info from (selected) expression;
- View expression info;
- View quick documentation;
- View quick definition;
- Structure view;
- Navigate to declaration (called
Class
in IntelliJ menu); - Navigate to identifier (called
Symbol
in IntelliJ menu); - Code completion by looking to import declarations;
- Simple form of code formatting;
- Inspection by HLint;
- Quick fixes for HLint suggestions;
- View error, action to view formatted message from ghc-mod. Especially useful in case message consists of multiple lines (Ctrl-F10, Meta-F10 on Mac OSX);
- Intention actions (suggested by ghc-mod);
A lot of features are with the help of ghc-mod(i)!!
- Cabal install latest versions of ghc-mod and haskell-docs;
- Set file paths to ghc-mod, ghc-modi, hlint and haskell-docs in
Settings/Haskell
. - Be sure in
Settings/Filetypes
thatHaskell language file
is registered with pattern*.hs
andLiterate Haskell language file
with pattern*.lhs
; - First install and build your project in a Cabal sandbox (be sure that Haddock documentation is generated, see haskell-docs).
- After project is built in sandbox, create Haskell project in IntelliJ by using
File
/New Project
from IntelliJ menu; - In
New Project
wizard createGHC SDK
by selecting path to GHC binaries, e.g.\usr\local\bin
; - Select in
Project settings
/Modules
which folders to exclude (like .cabal-sandbox and dist) and which folders areSource
andTest
(normally src and test). - To get nice navigation features: add for libraries and Prelude(base, ghc-prim and integer-gmp packages) the source root directories to project in
Project Settings
/Libraries
.cabal get
is useful for getting source code of package. To get source code of libraries inProject view
, create for example a directorylib
inside project root directory and put source roots there; - When you get an error like
NG BUG: GMECabalCompAssignment [(Left "lib/directory-1.2.1.0/System/Directory.hs",fromList [])]
, add the source root (in this examplelib/directory-1.2.1.0
) toProject Settings
/Libraries
because ghc-mod(i) does not support Haskell files which are not part of project itself; - Be sure all module names are directly or indirectly listed in Cabal file;
- ghc-mod does not support GHC < 7.10 and Cabal 1.22. See for more info the ghc-mod wiki. So in case you are using for example GHC 7.8.4, you will have to use Cabal 1.20.x;
- In Navigation dialog dots can not be used. Workaround is by using spaces instead of dots, so when you want to go to
Control.Lens
, typeControl Lens
; - IntelliJ has a nice terminal plugin, useful for executing the Cabal commands;
- ghc-mod can not help in library files and if Haskell source file contains not completely valid Haskell (e.g. while typing). In that case I try to solve request by using AST-tree (IntelliJ calls it PSI-tree).
- Because of ghc-mod issue #275 ghc-mod is used (instead of ghc-modi) for checking syntax of Haskell file;
- Because of ghc-mod issue #362 ghc-mod is used (instead of ghc-modi) for getting symbols of module using
browse
command. Performance for code completion will probably improve if I can use ghc-modi forbrowse
; - It would be nice if ghc-mod issue #303 would be solved. That would made it possible to get support from ghc-mod while type/syntax errors exist. For example, while typing.
Created workaround for this issue: https://youtrack.jetbrains.com/issue/IDEA-130894.- Developed plugin on Ubuntu;
- During testing on Mac OSX Yosemite Beta I noticed problem with ghc-modi: PATH environment variable asked from within IntelliJ was not the same as the global one. I had to create workaround only for Mac OSX :-(
This workaround will add path of
GHC SDK
to PATH environment variable which is passed to ghc-modi process. Other solutions are welcome! - Windows is not supported. Maybe it will work okay but I can not test it;
- Created workaround for ghc-mod issue #432;
I found an issue in IntelliJ 14.1, see https://youtrack.jetbrains.com/issue/IDEA-138236. Hopefully they will fix it soon;
- Clone this project;
- Clone IntelliJ Communitiy Edition (optional, it's needed to navigate to IntelliJ source code). Check out right tag by looking to version number;
- Install/enable plugins: Plugin Devkit, Grammar-Kit and PsiViewer;
- Open this project and check/change paths of
IntelliJ Platform Plugin SDK
. Also check/change path to it's sources (use root directory from step 2); - Check/change paths to Scala dependencies: scala-sdk, scalatest and spray-json;
- Navigate to
_HaskellLexer.flex
and runRun Flex Generator
. This will generate_HaskellLexer.java
; - Navigate to
haskell.bnf
and runGenerate Parser Code
. This will generate parser Java files ingen
directory; - Select
Make project
fromBuild
menu; - To run/debug this plugin select
intellij-haskell
inConfigurations
;