IntelliJ plugin for Haskell
Go to file
2016-12-29 15:43:02 +08:00
gen/intellij/haskell Improved parser. 2016-12-28 17:54:30 +01:00
intellij-haskell Update change notes. 2016-12-27 11:49:58 +01:00
logo Add plugin logo 2016-12-29 15:43:02 +08:00
project Upgrade to Scala 2.12.0 2016-11-24 13:23:57 +01:00
src Improved parser. 2016-12-28 17:54:30 +01:00
.gitignore Replace ghc-mod by stack repl 2016-09-01 15:30:12 +02:00
build.sbt Upgrade Guava library. 2016-12-09 14:06:50 +01:00
idea-flex.skeleton Replace ghc-mod by stack repl 2016-09-01 15:30:12 +02:00
LICENSE Various improvements including: 2014-06-25 16:52:52 +02:00
README.md Add plugin logo 2016-12-29 15:43:02 +08:00

logo IntelliJ plugin for Haskell

Join the chat at https://gitter.im/intellij-haskell/Lobby

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!!

Installing the plugin

You can install this plugin using the Jetbrains plugin repository: Settings/Plugins/Browse repositories/Intellij-Haskell

Features (1.0.0-beta4)

  • 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;
  • Navigate to declaration (called Navigate/Class in IntelliJ menu);
  • Navigate to identifier (called Navigate/Symbol in IntelliJ menu);
  • Navigate to declaration or identifier powered by Hoogle (called Navigate/Navigation by Hoogle in 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) or to add import of identifier;
  • Code formatting with Hindent and/or Stylish-haskell. Formatting of selected code by Hindent;

Getting started (1.0.0-beta4)

  • 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. Notice that currently 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 hindent Set file paths to hindent and stylish-haskell in the Settings/Other Settings/Haskell.
  • Make sure your Stack project builds without errors. Preferably by using: stack build --test --haddock --fast;
  • After your project is built, import project in IntelliJ by using File/New/Project from Existing Sources.. from the IntelliJ menu;
  • In the New Project wizard select Import project from external module and check Haskell Stack importer;
  • In next page of wizard configure Project SDK by configuring Haskell Tool Stack with selecting path to stack binary, 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, Haskell-docs and HLint to prevent incompatibility issues. Those tools are built against Stackage release defined in project's stack.yaml; If you want to use later version of tool, you will have to build tool manually in project's folder by using stack build;
  • Check Project structure/Project settings/Modules which folders to exclude (like .stack-work and dist) and which folders are Source and Test (normally src and test);
  • 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 ideaHaskellLib inside root of project
  • After changes to dependencies you can download them again by using Tools/Download Haskell library sources.
  • The Event Log will display what's going on in the background. Useful when something fails;
  • 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 to stack.yaml or Cabal file, you have to restart IntelliJ project;

Remarks

  1. Plugin does not support multi package projects;
  2. IntelliJ has a nice terminal plugin;
  3. Developed plugin on Linux. Also tested on OSX;
  4. Windows is not supported;
  5. About Haskell project in Help menu shows which Haskell GHC/tools are used by plugin for project;

How to build project

  1. Clone this project;
  2. Go to root of project and start sbt;
  3. Run task updateIdea from the sbt console;
  4. Run task compile from the sbt console;
  5. Install/enable the following plugins in IntelliJ: Plugin Devkit, Grammar-Kit and PsiViewer;
  6. Import this project as an sbt project in IntelliJ;
  7. Be sure JVM SDK inside Languages & Frameworks/Scala Compiler Server is set to 1.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;
  8. Select Build/Build Project;

How to prepare plugin for deployment

  1. Right click on top of intellij-haskell.iml inside intellij-haskell folder;
  2. Select Import module;
  3. Be sure unmanaged-jars dependency is set to provided inside Project structure/Project settings/Modules/Dependencies (btw, setting provided inside sbt file gives error);
  4. Right click on top of intellij-haskell plugin module and select Prepare Plugin Module 'intellij-haskell' for deployment;

How to run/debug plugin inside IntelliJ

  1. Set Plugin SDK settings right inside Project structure/Platform settings/SDKs. For example to, set SDK home path to idea/142.5239.7 inside project root folder;
  2. Set Module-SDK right for intellij-haskell plugin module inside Project structure/Project structure/Project settings/Modules;
  3. To run plugin inside IntelliJ, first run configuration has to be created. Navigate to Run/Edit configurations and create plugin configuration for intellij-haskell;

Development remarks

  1. After making changes to _HaskellLexer.flex, run Run Flex Generator. This will generate _HaskellLexer.java;
  2. After making changes to haskell.bnf, run Generate Parser Code. This will generate parser Java files in gen directory;
  3. Add sources.zip inside idea/[idea build #] to Project structure/Project settings/Modules/Dependencies/unmanaged-jars to see IntelliJ sources;