• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

haskell/haskell-ide-engine: The engine for haskell ide-integration. Not an IDE

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

haskell/haskell-ide-engine

开源软件地址(OpenSource Url):

https://github.com/haskell/haskell-ide-engine

开源编程语言(OpenSource Language):

Haskell 99.5%

开源软件介绍(OpenSource Introduction):

Deprecated

This repository is now an historical artifact. It was the original LSP support for haskell, which is now provided by

https://github.com/haskell/haskell-language-server

Haskell IDE Engine (HIE)

License BSD3 CircleCI Azure Pipeline AppVeyor Open Source Helpers

This project aims to be the universal interface to a growing number of Haskell tools, providing a fully-featured Language Server Protocol server for editors and IDEs that require Haskell-specific functionality.

Features

  • Supports plain GHC projects, cabal projects(sandboxed and non sandboxed) and stack projects

  • Fast due to caching of compile info

  • Uses LSP, so should be easy to integrate with a wide selection of editors

  • Diagnostics via hlint and GHC warnings/errors

    Diagnostics

  • Code actions and quick fixes via apply-refact

    Apply Refact

  • Type information and documentation(via haddock) on hover

    Hover

  • Jump to definition

    Find Def

  • List all top level definitions

    Doc Symbols

  • Highlight references in document

    Doc Highlight

  • Completion

    Completion

  • Formatting via brittany

    Formatting

  • Renaming via HaRe (NOTE: HaRe is temporarily disabled)

    Renaming

  • Add packages to cabal and hpack package files

    Adding package to hpack Adding import & deps

  • Typo quick fixes

    Quick fixes

  • Add missing imports (via hsimport)

    Missing imports

Installation

Installation with Nix

Follow the instructions at https://github.com/Infinisil/all-hies

Installation on Arch Linux

A haskell-ide-engine package is available on the AUR.

Install it using Aura:

# aura -A haskell-ide-engine

To change which GHC versions are supported by HIE, use

# aura -A --hotedit haskell-ide-engine

and modify the value of _enabled_ghc_versions.

Reducing the number of supported GHC versions makes HIE compile faster.

Installation with GHC and HIE as a VS Code Devcontainer

VS Code provides the ability to develop applications inside of a Docker container (called Devcontainers) https://code.visualstudio.com/docs/remote/containers

There is a community Devcontainer setup which installs and configures GHC + HIE 8.6.5 and the necessary VS Code extensions to integrate them into the editor.

https://github.com/hmemcpy/haskell-hie-devcontainer

Installation from source

To install HIE, you need stack version >= 2.1.1.

HIE builds from source code, so there's a couple of extra steps.

Common pre-requirements

  • stack must be in your PATH
  • git must be in your PATH
  • Stack local bin directory must be in your PATH. Get it with stack path --local-bin

Tip: you can quickly check if some command is in your path by running the command. If you receive some meaningful output instead of "command not found"-like message then it means you have the command in PATH.

Linux-specific pre-requirements

On Linux you will need install a couple of extra libraries (for Unicode (ICU) and NCURSES):

Debian 9/Ubuntu 18.04 or earlier:

sudo apt install libicu-dev libtinfo-dev libgmp-dev

Debian 10/Ubuntu 18.10 or later:

sudo apt install libicu-dev libncurses-dev libgmp-dev # also zlib1g-dev if not installed

Fedora:

sudo dnf install libicu-devel ncurses-devel # also zlib-devel if not already installed

Windows-specific pre-requirements

In order to avoid problems with long paths on Windows you can do either one of the following:

  1. Clone the haskell-ide-engine to a short path, for example the root of your logical drive (e.g. to C:\hie). If this doesn't work or you want to use a longer path, try the second option.

  2. If the Local Group Policy Editor is available on your system, go to: Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem set Enable Win32 long paths to Enabled. If you don't have the policy editor you can use regedit by using the following instructions here. You also need to configure git to allow longer paths by using unicode paths. To set this for all your git repositories use git config --system core.longpaths true (you probably need an administrative shell for this) or for just this one repository use git config core.longpaths true.

In addition make sure hie.exe is not running by closing your editor, otherwise in case of an upgrade the executable can not be installed.

Download the source code

git clone https://github.com/haskell/haskell-ide-engine --recurse-submodules
cd haskell-ide-engine

Building

Uses the shake build system for predictable builds.

Note, on first invocation of the build script, a GHC is being installed for execution. The GHC used for the install.hs can be adjusted in shake.yaml by using a different resolver.

Available commands can be seen with:

stack ./install.hs help

Remember, this will take time to download a Stackage-LTS and an appropriate GHC. However, afterwards all commands should work as expected.

Install via cabal

The install-script can be invoked via cabal instead of stack with the command

cabal v2-run ./install.hs --project-file install/shake.project <target>

or using the existing alias script

./cabal-hie-install <target>

Running the script with cabal on windows requires a cabal version greater or equal to 3.0.0.0.

For brevity, only the stack-based commands are presented in the following sections.

Install specific GHC Version

Install hie for the latest available and supported GHC version (and hoogle docs):

stack ./install.hs hie

Install hie for a specific GHC version (and hoogle docs):

stack ./install.hs hie-8.6.5
stack ./install.hs data

The Haskell IDE Engine can also be built with cabal v2-build instead of stack build. This has the advantage that you can decide how the GHC versions have been installed. To see what GHC versions are available, the command cabal-hie-install ghcs can be used. It will list all GHC versions that are on the path and their respective installation directory. If you think, this list is incomplete, you can try to modify the PATH variable, such that the executables can be found. Note, that the targets hie and data depend on the found GHC versions. They install Haskell IDE Engine only for the found GHC versions.

An example output is:

> cabal-hie-install ghcs
******************************************************************
Found the following GHC paths:
ghc-8.4.4: /opt/bin/ghc-8.4.4
ghc-8.6.2: /opt/bin/ghc-8.6.2

******************************************************************

If your desired ghc has been found, you use it to install Haskell IDE Engine.

cabal-hie-install hie-8.4.4
cabal-hie-install data

In general, executing targets with cabal instead of stack have the same behaviour, except they do not install a GHC if it is missing but fail.

Multiple versions of HIE (optional)

If you installed multiple versions of HIE then you will need to use a wrapper script. Wrapper script will analyze your project, find suitable version of HIE and launch it. Enable it by editing VS Code settings like this:

"haskell.useCustomHieWrapper": true,
"haskell.useCustomHieWrapperPath": "hie-wrapper",

Configuration

There are some settings that can be configured via a settings.json file:

{
    "haskell": {
        "hlintOn": Boolean,
        "maxNumberOfProblems": Number
        "diagnosticsDebounceDuration" : Number
        "liquidOn"                    : Bool (default False)
        "completionSnippetsOn"        : Bool (default True)
        "formatOnImportOn"            : Bool (default True)
        "formattingProvider"          : String (default "brittany",
                                                alternate "floskell")
    }
}
  • VS Code: These settings will show up in the settings window
  • LanguageClient-neovim: Create this file in $projectdir/.vim/settings.json or set g:LanguageClient_settingsPath

Project Configuration

For a full explanation of possible configurations, refer to hie-bios/README.

HIE will attempt to automatically detect your project configuration and set up the environment for GHC.

cabal.project stack.yaml *.cabal Project selected
- - Cabal v2
- Stack
Cabal (v2 or v1)
None

However, you can also place a hie.yaml file in the root of the workspace to explicitly describe how to setup the environment. For example, to state that you want to use stack then the configuration file would look like:

cradle:
  stack:
    component: "haskell-ide-engine:lib"

If you use cabal then you probably need to specify which component you want to use.

cradle:
  cabal:
    component: "lib:haskell-ide-engine"

If you have a project with multiple components, you can use a cabal-multi cradle:

cradle:
  cabal:
    - path: "./test/dispatcher/"
      component: "test:dispatcher-test"
    - path: "./test/functional/"
      component: "test:func-test"
    - path: "./test/unit/"
      component: "test:unit-test"
    - path: "./hie-plugin-api/"
      component: "lib:hie-plugin-api"
    - path: "./app/MainHie.hs"
      component: "exe:hie"
    - path: "./app/HieWrapper.hs"
      component: "exe:hie-wrapper"
    - path: "./"
      component: "lib:haskell-ide-engine"

Equivalently, you can use stack:

cradle:
  stack:
    - path: "./test/dispatcher/"
      component: "haskell-ide-engine:test:dispatcher-test"
    - path: "./test/functional/"
      component: "haskell-ide-engine:test:func-test"
    - path: "./test/unit/"
      component: "haskell-ide-engine:test:unit-test"
    - path: "./hie-plugin-api/"
      component: "hie-plugin-api:lib"
    - path: "./app/MainHie.hs"
      component: "haskell-ide-engine:exe:hie"
    - path: "./app/HieWrapper.hs"
      component: "haskell-ide-engine:exe:hie-wrapper"
    - path: "./"
      component: "haskell-ide-engine:lib"

Or you can explicitly state the program which should be used to collect the options by supplying the path to the program. It is interpreted relative to the current working directory if it is not an absolute path.

cradle:
  bios:
    program: ".hie-bios"

The complete configuration is a subset of

cradle:
  cabal:
    component: "optional component name"
  stack:
    component: "optional component name"
  bios:
    program: "program to run"
    dependency-program: "optional program to run"
  direct:
    arguments: ["list","of","ghc","arguments"]
  default:
  none:

dependencies:
  - someDep

There is also support for multiple cradles in a single hie.yaml. An example configuration for Haskell IDE Engine:

cradle:
  multi:
    - path: ./test/dispatcher/
      config:
        cradle:
          cabal:
            component: "test:dispatcher-test"
    - path: ./test/functional/
      config:
        cradle:
          cabal:
            component: "test:func-test"
    - path: ./test/unit/
      config:
        cradle:
          cabal:
            component: "test:unit-test"
    - path: ./hie-plugin-api/
      config:
        cradle:
          cabal:
            component: "lib:hie-plugin-api"
    - path: ./app/MainHie.hs
      config:
        cradle:
          cabal:
            component: "exe:hie"
    - path: ./app/HieWrapper.hs
      config:
        cradle:
          cabal:
            component: "exe:hie-wrapper"
    - path: ./
      config:
        cradle:
          cabal:
            component: "lib:haskell-ide-engine"

Editor Integration

Note to editor integrators: there is now a hie-wrapper executable, which is installed alongside the hie executable. When this is invoked in the project root directory, it attempts to work out the GHC version used in the project, and then launch the matching hie executable.

All of the editor integrations assume that you have already installed HIE (see above) and that stack put the hie binary in your path (usually ~/.local/bin on linux and macOS).

Using HIE with VS Code

Install from the VSCode marketplace, or manually from the repository vscode-hie-server.

Using VS Code with Nix

.config/nixpkgs/config.nix sample:

with import <nixpkgs> {};

let
  hie = (import (fetchFromGitHub {
                   owner="domenkozar";
                   repo="hie-nix";
                   rev="e3113da";
                   sha256="05rkzjvzywsg66iafm84xgjlkf27yfbagrdcb8sc9fd59hrzyiqk";
                 }) {}).hie84;
in
{
  allowUnfree = true;
  packageOverrides = pkgs: rec {

    vscode = pkgs.vscode.overrideDerivation (old: {
      postFixup = ''
        wrapProgram $out/bin/code --prefix PATH : ${lib.makeBinPath [hie]}
      '';
    });

  };
}

Using HIE with Sublime Text

  • Make sure HIE is installed (see above) and that the directory stack put the hie binary in is in your path
    • (usually ~/.local/bin on unix)
  • Install LSP using Package Control
  • From Sublime Text, press Command+Shift+P and search for Preferences: LSP Settings
  • Paste in these settings. Make sure to change the command path to your hie
{
"clients": {
  "haskell-ide-engine": {
    "command": ["hie", "--lsp"],
    "scopes": ["source.haskell"],
    "syntaxes": ["Packages/Haskell/Haskell.sublime-syntax"],
    "languageId": "haskell",
  },
},
}

Now open a Haskell project with Sublime Text. You should have these features available to you:

  1. Errors are underlined in red
  2. LSP: Show Diagnostics will show a list of hints and errors
  3. LSP: Format Document will prettify the file

Using HIE with Vim or Neovim

As above, make sure HIE is installed. Then you can use Coc, LanguageClient-neovim or any other vim Langauge server protocol client. Coc is recommend since it is the only complete LSP implementation for Vim and Neovim and offers snippets and floating documentation out of the box.

Coc

Follow Coc's installation instructions, Then issue :CocConfig and add the following to your Coc config file.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap