When I was learning Haskell, I missed the nice features of IntelliJ IDEA. My first approach was to use default way of creating an IntelliJ plugin by defining a grammar and a lexer according to Haskell report. That didn't work out because I could not define all the recursion. Then I decided to use grammar and lexer definitions only for tokenizing and parsing Haskell code, and not for syntax checking the code. This is needed for syntax highlighting, all kinds of navigation and so on. Further Haskell language support is provided with the help of external tools.
This plugin depends mainly on Stack and Intero. It can create new Stack projects (by using template hspec) and import existing Stack projects.
Any feedback is welcome!!
You can install this plugin using the Jetbrains plugin repository:
Settings/Plugins/Browse repositories/Intellij-Haskell
- Syntax highlighting;
- Error/warning highlighting;
- Find usages of identifiers;
- Resolve references to identifiers;
- Code completion;
- In-place rename identifiers;
- View type info from (selected) expression;
- View expression info;
- View quick documentation;
- View quick definition;
- Structure view;
- Goto to declaration (called
Navigate/Declarationin IntelliJ menu); - Navigate to declaration (called
Navigate/Classin IntelliJ menu); - Navigate to identifier (called
Navigate/Symbolin IntelliJ menu); - Goto instance declaration (called
Navigate/Instance Declarationin IntelliJ menu); - Navigate to declaration or identifier powered by Hoogle (called
Navigate/Navigation by Hooglein IntelliJ menu); - Inspection by HLint;
- Quick fixes for HLint suggestions;
- Show error action to view formatted message. Useful in case message consists of multiple lines (Ctrl-F10, Meta-F10 on Mac OSX);
- Intention actions to add language extension (depends on compiler error), add top-level type signature (depends on compiler warning);
- Intention action to select which module to import if identifier is not in scope;
- Code formatting with Hindent and/or Stylish-haskell. Formatting of selected code by Hindent;
- Code completion for project module names, language extensions and package names in Cabal file;
- Install this plugin. Make sure no other Haskell plugin is installed in IntelliJ;
- Install latest version of Stack;
- Install latest versions of Hindent and Stylish-Haskell.
Note that currently the latest version of Hindent is not on Stackage LTS. You have to install version of Hindent > 5.0, for example by:
stack install --resolver nightly-2016-11-06 hindentSet file paths tohindentandstylish-haskellin theSettings/Other Settings/Haskell; - Setup the project:
- Make sure your Stack project builds without errors. Preferably by using:
stack build --test --haddock --fast; - After your project is built successfully, import project in IntelliJ by using
File/New/Project from Existing Sources...from the IntelliJ menu; - In the
New Projectwizard selectImport project from external moduleand checkHaskell Stack; - In next page of wizard configure
Project SDKby configuringHaskell Tool Stackwith selecting path tostackbinary, e.g./usr/local/bin/stack; - Finish wizard and project will be opened;
- Wizard will try to automatically configure which folders are sources, test and which to exclude;
- Plugin will automatically build Intero and HLint to prevent incompatibility issues
(If you use non LTS or Nightly resolver e.g.
ghc-7.10.2, you may have to build them manually since there are some extra-deps should be added tostack.yaml). Those tools are built against Stackage release defined in project'sstack.yaml. If you want to use later version of tool, you will have to build tool manually in project's folder by usingstack build; - Check
Project structure/Project settings/Moduleswhich folders to exclude (like.stack-workanddist) and which folders areSourceandTest(normallysrcandtest); - Plugin will automatically download library sources (since Stack version 1.2.1 also for test dependencies). They will be added as source libraries to module.
This option gives you nice navigation features through libraries. Sources are downloaded to folder
.ideaHaskellLibinside root of project; - After changes to dependencies you can download them again by using
Tools/Download Haskell Library Sources; - The
Event Logwill display what's going on in the background. Useful when something fails. It's disabled by default. It can be enabled by checkingHaskell Logcheckbox in theEvent LogSettings; - In the background for each Haskell project two Stack repls are running. You can restart them by
Tools/Restart Haskell Stack REPLs. When you make large changes tostack.yamlor Cabal file, you have to restart IntelliJ project;
- Make sure your Stack project builds without errors. Preferably by using:
- Plugin does not support multi package projects;
- IntelliJ has a nice terminal plugin;
- Developed plugin on Linux. Also tested on OSX;
- Windows is not supported;
About Haskell ProjectinHelpmenu shows which Haskell GHC/tools are used by plugin for project;- Intero depends on
libtinfo-dev. On Ubuntu you can install it withsudo apt-get install libtinfo-dev;
- Clone this project;
- Go to root of project and start sbt;
- Run task
updateIdeafrom the sbt console; - Run task
compilefrom the sbt console; - Install/enable the following plugins in IntelliJ: Plugin Devkit, Grammar-Kit and PsiViewer;
- Import this project as an sbt project in IntelliJ;
- Be sure
JVM SDKinsideLanguages & Frameworks/Scala Compiler Serveris set to1.8, since the Scala compiler version (2.12.1) which this plugin is currently using is not compatible with Java 7 or lower, Java 9 is not yet supported; - Select
Build/Build Project;
- Right click on top of
intellij-haskell.imlinsideintellij-haskellfolder; - Select
Import module; - Be sure
unmanaged-jarsdependency is set toprovidedinsideProject structure/Project settings/Modules/Dependencies(btw, settingprovidedinside sbt file gives error); - Right click on top of
intellij-haskellplugin module and selectPrepare Plugin Module 'intellij-haskell' for deployment;
- Set Plugin SDK settings right inside
Project structure/Platform settings/SDKs. For example to, set SDK home path toidea/142.5239.7inside project root folder; - Set
Module-SDKright forintellij-haskellplugin module insideProject structure/Project structure/Project settings/Modules; - To run plugin inside IntelliJ, first run configuration has to be created. Navigate to
Run/Edit configurationsand createpluginconfiguration forintellij-haskell;
- After making changes to
_HaskellLexer.flex, runRun Flex Generator. This will generate_HaskellLexer.java; - After making changes to
haskell.bnf, runGenerate Parser Code. This will generate parser Java files ingendirectory; - Add
sources.zipinsideidea/[idea build #] toProject structure/Project settings/Modules/Dependencies/unmanaged-jarsto see IntelliJ sources;