Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete editor integrations #132

Merged
merged 14 commits into from
May 27, 2020
166 changes: 157 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ This is *very* early stage software.
- [Install specific GHC Version](#install-specific-ghc-version)
- [Project Configuration](#project-configuration)
- [Editor Integration](#editor-integration)
- [With emacs](#using-haskell-language-server-with-emacs)
- [With doom emacs](#using-haskell-language-server-with-doom-emacs)
- [With Kakoune](#using-haskell-language-server-with-kakoune)
- [VS Code](#using-haskell-language-server-with-vs-code)
- [Sublime Text](#using-haskell-language-server-with-sublime-text)
- [Vim or Neovim](#using-haskell-language-server-with-vim-or-neovim)
- [Coc](#coc)
- [LanguageClient-neovim](#languageclient-neovim)
- [vim-plug](#vim-plug)
- [Clone the LanguageClient-neovim repo](#clone-the-languageclient-neovim-repo)
- [Sample `~/.vimrc`](#sample-vimrc)
- [Atom](#using-haskell-language-server-with-atom)
- [Emacs](#using-haskell-language-server-with-emacs)
- [Doom emacs](#using-haskell-language-server-with-doom-emacs)
- [Kakoune](#using-haskell-language-server-with-kakoune)
- [Contributing](#contributing)
- [It's time to join the project!](#its-time-to-join-the-project)

Expand Down Expand Up @@ -273,9 +282,150 @@ dependencies:

## Editor Integration

Note to editor integrators: there is now a haskell-language-server-wrapper executable, which is installed alongside the haskell-language-server 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 haskell-language-server executable.
Note to editor integrators: there is a haskell-language-server-wrapper executable, which is installed alongside the haskell-language-server 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 haskell-language-server executable.
jneira marked this conversation as resolved.
Show resolved Hide resolved

All of the editor integrations assume that you have already installed haskell-language-server (see above) and that the installation script put the haskell-language-server binary in your path (usually `~/.local/bin` or `~/.cabal/bin` on linux and macOS).
All of the editor integrations assume that you have already installed haskell-language-server (see above) and that the installation script put the haskell-language-server and haskell-language-server-wrapper binaries in your path (usually `~/.local/bin` or `~/.cabal/bin` on linux and macOS, `%APPDATA%\local\bin` or `%APPDATA%\cabal\bin` in windows).
jneira marked this conversation as resolved.
Show resolved Hide resolved

### Using Haskell Language Server with VS Code

Install from
[the VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=alanz.vscode-hie-server), or manually from the repository [vscode-hie-server](https://github.com/alanz/vscode-hie-server).

Choose `haskell-language-server` in the extension setting `languageServerHaskell.hieVariant`.

### Using Haskell Language Server with Sublime Text

- Make sure haskell-language-server and haskell-language-server-wrapper are installed (see above) and they are in the global `$PATH`.
jneira marked this conversation as resolved.
Show resolved Hide resolved
- Install [LSP](https://packagecontrol.io/packages/LSP) using [Package Control](https://packagecontrol.io/)
- From Sublime Text, press Command+Shift+P and search for Preferences: LSP Settings
jneira marked this conversation as resolved.
Show resolved Hide resolved
- Paste in these settings. Make sure to change the command path to your `hie`
jneira marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"clients": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be indented once here? E.g.

{
  "clients": {
    "haskell-ide-engine": {
      "command": ["haskell-language-server-wrapper", "--lsp"],
      "scopes": ["source.haskell"],
      "syntaxes": ["Packages/Haskell/Haskell.sublime-syntax"],
      "languageId": "haskell",
    },
  },
}

Also, is it normal that there are commas at the end of each line? I think some systems support it, but just wanted to be sure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name should be changed from haskell-ide-engine to haskell-language-server

Copy link
Member Author

@jneira jneira May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not sure if those keys are hardcoded or can be changed (i am not using sublime). We are using plugins that are intended to be usable by hie.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested earlier today (installed Sublime etc. as I'm not a Sublime user), and I can confirm this works well with whatever name you choose: actually this is used by Sublime LSP plugin to help the user choose which LSP to enable, as per my screenshot:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow thanks for trying it, will change

"haskell-ide-engine": {
"command": ["haskell-language-server-wrapper", "--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:
jneira marked this conversation as resolved.
Show resolved Hide resolved

jneira marked this conversation as resolved.
Show resolved Hide resolved
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 Haskell Language Server with Vim or Neovim

As above, make sure haskell-language-server and haskell-language-server-wrapper are installed.
jneira marked this conversation as resolved.
Show resolved Hide resolved
Then you can use [Coc](https://github.com/neoclide/coc.nvim), [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
or any other vim Language server protocol client.
jneira marked this conversation as resolved.
Show resolved Hide resolved
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](https://github.com/neoclide/coc.nvim),
jneira marked this conversation as resolved.
Show resolved Hide resolved
Then issue `:CocConfig` and add the following to your Coc config file.

```jsonc
jneira marked this conversation as resolved.
Show resolved Hide resolved
"languageserver": {
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp"],
"rootPatterns": [
"*.cabal",
"stack.yaml",
"cabal.project",
"package.yaml"
],
"filetypes": [
"hs",
"lhs",
"haskell"
],
"initializationOptions": {
"languageServerHaskell": {
}
}
}
}
```

#### LanguageClient-neovim

##### vim-plug

If you use [vim-plug](https://github.com/junegunn/vim-plug), then you can do this by e.g.,
including the following line in the Plug section of your `init.vim` or `~/.vimrc`:

```text
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': './install.sh'
jneira marked this conversation as resolved.
Show resolved Hide resolved
\ }
```

and issuing a `:PlugInstall` command within Neovim or Vim.

##### Clone the LanguageClient-neovim repo

As an alternative to using [vim-plug](https://github.com/junegunn/vim-plug) shown above, clone [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
into `~/.vim/pack/XXX/start/`, where `XXX` is just a name for your "plugin suite".

##### Sample `~/.vimrc`

```vim
set rtp+=~/.vim/pack/XXX/start/LanguageClient-neovim
let g:LanguageClient_serverCommands = { 'haskell': ['haskell-language-server-wrapper', '--lsp'] }
```

You'll probably want to add some mappings for common commands:

```vim
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
map <Leader>lk :call LanguageClient#textDocument_hover()<CR>
map <Leader>lg :call LanguageClient#textDocument_definition()<CR>
map <Leader>lr :call LanguageClient#textDocument_rename()<CR>
map <Leader>lf :call LanguageClient#textDocument_formatting()<CR>
map <Leader>lb :call LanguageClient#textDocument_references()<CR>
map <Leader>la :call LanguageClient#textDocument_codeAction()<CR>
map <Leader>ls :call LanguageClient#textDocument_documentSymbol()<CR>
```

Use <kbd>Ctrl+x</kbd><kbd>Ctrl+o</kbd> (`<C-x><C-o>`) to open up the auto-complete menu,
or for asynchronous auto-completion, follow the setup instructions on
[LanguageClient](https://github.com/autozimu/LanguageClient-neovim).

If you'd like diagnostics to be highlighted, add a highlight group for `ALEError`/`ALEWarning`/`ALEInfo`,
or customize `g:LanguageClient_diagnosticsDisplay`:

```vim
hi link ALEError Error
hi Warning term=underline cterm=underline ctermfg=Yellow gui=undercurl guisp=Gold
hi link ALEWarning Warning
hi link ALEInfo SpellCap
```

If you're finding that the server isn't starting at the correct project root,
it may also be helpful to also specify root markers:

```vim
let g:LanguageClient_rootMarkers = ['*.cabal', 'stack.yaml']
```

### Using Haskell Language Server with Atom

Make sure haskell-language-server and haskell-language-server-wrapper are installed, then install the two Atom packages [atom-ide-ui](https://atom.io/packages/atom-ide-ui) and [ide-haskell-hie](https://atom.io/packages/ide-haskell-hie),
jneira marked this conversation as resolved.
Show resolved Hide resolved

```bash
$ apm install language-haskell atom-ide-ui ide-haskell-hie
```

The plugin ide-haskell-ide is designed to work with haskell-ide-engine by default, so you will have to put the path to haskell-language-server-wrapper in the configuration option `Absolute path to hie executable`.
jneira marked this conversation as resolved.
Show resolved Hide resolved
jneira marked this conversation as resolved.
Show resolved Hide resolved

### Using haskell-language-server with Emacs

Expand All @@ -297,11 +447,10 @@ Make sure to follow the instructions in the README of each of these packages.
)
```



### Using haskell-language-server with [doom-emacs](https://github.com/hlissner/doom-emacs/tree/develop/modules/lang/haskell#module-flags)

Install haskell-language-server, and then enable haskell lang module with lsp flag in `.doom.d/init.el`

``` emacs-lisp
:lang
(haskell +lsp)
Expand All @@ -321,7 +470,6 @@ in your `.doom.d/config.el` file

then do `$HOME/.emacs.d/bin/doom refresh`


### Using haskell-language-server with [Kakoune](https://github.com/mawww/kakoune)

1. Grab a copy of [kak-lsp](https://github.com/ul/kak-lsp), and follow the setup instructions.
Expand All @@ -337,7 +485,7 @@ args = ["--lsp"]

## Contributing

### It's time to join the project!
### It's time to join the project

:heart: Haskell tooling dream is near, we need your help! :heart:

Expand Down