Coder Social home page Coder Social logo

intellij-haskell's Introduction

IntelliJ plugin for Haskell

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

Features

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

Getting started:

  • 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 that Haskell language file is registered with pattern *.hs and Literate 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 create GHC 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 are Source and Test (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 in Project view, create for example a directory lib 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 example lib/directory-1.2.1.0) to Project 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;

Remarks

  • 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, type Control 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 for browse;
  • 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;

How to build

  1. Clone this project;
  2. Clone IntelliJ Communitiy Edition (optional, it's needed to navigate to IntelliJ source code). Check out right tag by looking to version number;
  3. Install/enable plugins: Plugin Devkit, Grammar-Kit and PsiViewer;
  4. 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);
  5. Check/change paths to Scala dependencies: scala-sdk, scalatest and spray-json;
  6. Navigate to _HaskellLexer.flex and run Run Flex Generator. This will generate _HaskellLexer.java;
  7. Navigate to haskell.bnf and run Generate Parser Code. This will generate parser Java files in gen directory;
  8. Select Make project from Build menu;
  9. To run/debug this plugin select intellij-haskell in Configurations;

intellij-haskell's People

Contributors

rikvdkleij avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.