intellij-haskell 0

IntelliJ plugin for Haskell

2 years after Apache-2.0

IntelliJ plugin for Haskell

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 support of external tools: ghc-mod and haskell-docs.

It supports Stack projects and expects that creating and building of Haskell projects is done on the command line.

Any feedback is welcome!!

Features

  • Syntax highlighting (which can be customized);
  • Error/warning highlighting;
  • Find usages of identifiers;
  • Resolve references to identifiers (also in libraries if packages source code are available by using Tools /Add Haskell package dependencies);
  • Code completion by resolving references;
  • In-place 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 implemented with help of ghc-mod!!

Getting started:

  • Install latest versions of ghc-mod and haskell-docs;
  • Set file paths to ghc-mod, hlint, stack and haskell-docs in the menu Settings/Other Settings/Haskell.
  • Be sure in Editor/Filetypes that Haskell language file is registered with pattern *.hs and Literate Haskell language file with pattern *.lhs;
  • First install and build your project. Preferably with Stack. (Make sure that Haddock documentation is generated, see haskell-docs).
  • After the project is built, create a Haskell project in IntelliJ by using File/New/Project... from the IntelliJ menu;
  • In the New Project wizard select Haskell module and check Haskell in Additional Libraries and Frameworks;
  • In next page of wizard create GHC SDK by selecting path to GHC binaries, e.g. /usr/local/bin;
  • Select in 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).
  • Use Tools/Add Haskell package dependencies to download all sources of 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

Remarks

  • 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, type Control Lens;
  • IntelliJ has a nice terminal plugin, useful for executing the Cabal/Stack commands;
  • Developed plugin on Ubuntu;
  • Windows is not supported. Maybe it will work okay but I can not test it;
  • Created workaround for ghc-mod issue #432;

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. Select Build/Make 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;

Related Repositories

solarized

solarized

precision color scheme for multiple applications (terminal, vim, etc.) with both ...

awesome-rust

awesome-rust

A curated list of Rust code and resources. ...

awesome-rust

awesome-rust

A curated list of Rust code and resources. ...

frege

frege

Frege is a Haskell for the JVM. It brings purely functional programing to the Ja ...

intellij-colors-solarized

intellij-colors-solarized

Solarized Colorscheme for IntelliJ IDEA ...


Top Contributors

rikvdkleij Oblosys epost zjhmale

Releases

-   v0.92 zip tar
-   v0.91 zip tar
-   v0.81 zip tar
-   v0.9 zip tar
-   v0.9-beta zip tar
-   v0.8 zip tar
-   v0.7 zip tar
-   v0.6 zip tar
-   v0.6beta5 zip tar
-   v0.6beta4 zip tar
-   v0.6beta3 zip tar
-   v0.6beta2 zip tar
-   v0.6beta zip tar
-   v0.5 zip tar
-   v0.4 zip tar
-   v0.3 zip tar
-   v0.2 zip tar
-   v0.1 zip tar