A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://haskell-language-server.readthedocs.io/en/latest/configuration.html below:

Website Navigation


Configuration — haskell-language-server 2.11.0.0 documentation

Configuration Configuring haskell-language-server

Language servers like haskell-language-server expose most of their configuration via the client (i.e. the editor). That means that the way in which you configure the settings will depend on the client.

Most clients (editors) already have an opinion about how settings should be configured! For example, in VS Code you use the graphical Settings tab or settings.json, whereas in Emacs you use customization variables. In the editor configuration section we give some pointers for popular editors, but you should consult the documentation for your specific editor if you have trouble.

However, we can say some high-level things about the kinds of configuration haskell-language-server uses, and how to use them. This can sound a bit confusing, but ultimately the client should present you with these options in a user-friendly way that makes sense for that editor.

Generic server options

The LSP protocol is designed to support many useful server configuration options generically. These are sent to the server by the client, and can be controlled without reference to a specific language.

For example, there are protocol methods for highlighting matching identifiers throughout a document. This is a capability that any server can implement, so the client can decide generically whether to ask the server to do it or not. So your editor can provide a setting to turn this on or off globally, for any language server you might use.

Settings like this are typically provided by the generic LSP client support for your editor, for example in Emacs by lsp-mode.

Generic editor options

Your editor may provide some settings that affect how the information from the language server is used. For example, whether popups are shown, or whether code lenses appear by default.

Settings like this are typically provided by the generic LSP client support for your editor, for example in Emacs by lsp-mode.

Language-specific server options

A specific language server can also have its own configuration options. These are still sent to the server by the client, but they can only be controlled by a specific client that knows about those options.

For example, haskell-language-server allows you to choose the formatting provider which will be used for formatting Haskell source. This option obviously would not make sense for language servers for other languages, or even for other Haskell language servers (which need not even support formatting).

Here is a list of the additional settings currently supported by haskell-language-server, along with their setting key (you may not need to know this) and default:

Generic plugin configuration

Plugins have a generic config to control their behaviour. The schema of such config is:

Settings like this are typically provided by the language-specific LSP client support for your editor, for example in Emacs by lsp-haskell.

Client options

A particular client might also have some options of its own, for example to control how the server executable is started.

Settings like this are typically be provided by the language-specific LSP client support for your editor, for example in Emacs by lsp-haskell.

Configuring your project build

haskell-language-server has to compile your project in order to give you diagnostics, which means that it needs to know how to do so. This is handled under the hood by the hie-bios application. In turn, hie-bios needs some configuration to identify all files, GHC options, etc., needed to compile a project.

There are several ways to provide this configuration to hie-bios, detailed below.

Implicit configuration

If no hie.yaml file is present, haskell-language-server automatically detects your hie-bios configuration using implicit-hie. For most cases, this works just fine, and is the recommended way.

Explicit, generated configuration

Maybe using the implicit configuration does not suit you. E.g., it does not work, or you prefer to have explicit configuration in your project. In that case, you can automatically generate a hie.yaml file, using implicit-hie:

gen-hie > hie.yaml  # In the root directory of your project
Explicit, manual configuration

Maybe using the generated hie.yaml file does not suit you. E.g., it still does not work, or you want to fine-tune the configuration.

In that case, refer to the hie-bios explicit configuration documentation. Keep in mind that you can start from the hie.yaml file generated by implicit-hie (see previous section) and modify it to your liking.

Examples of explicit hie.yaml configurations Basic Stack Basic Cabal Single Stack component
cradle:
  stack:
    component: "haskell-language-server:lib"
Single Cabal component
cradle:
  cabal:
    component: "lib:haskell-language-server"
Multiple Stack components
cradle:
  stack:
    - path: "./test/functional/"
      component: "haskell-language-server:func-test"
    - path: "./exe/Main.hs"
      component: "haskell-language-server:exe:haskell-language-server"
    - path: "./exe/Wrapper.hs"
      component: "haskell-language-server:exe:haskell-language-server-wrapper"
    - path: "./src"
      component: "haskell-language-server:lib"
    - path: "./ghcide/src"
      component: "ghcide:lib:ghcide"
    - path: "./ghcide/exe"
      component: "ghcide:exe:ghcide"
Multiple Cabal components
cradle:
  cabal:
    - path: "./test/functional/"
      component: "haskell-language-server:func-test"
    - path: "./test/utils/"
      component: "haskell-language-server:hls-test-utils"
    - path: "./exe/Main.hs"
      component: "haskell-language-server:exe:haskell-language-server"
    - path: "./exe/Wrapper.hs"
      component: "haskell-language-server:exe:haskell-language-server-wrapper"
    - path: "./src"
      component: "lib:haskell-language-server"
    - path: "./ghcide/src"
      component: "ghcide:lib:ghcide"
    - path: "./ghcide/exe"
      component: "ghcide:exe:ghcide"
Custom program

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
How to show local documentation on hover

Haskell Language Server can display Haddock documentation on hover and completions if the project and its dependencies have been built with the -haddock GHC flag.

Configuring your editor

Most editors provide a Haskell-specific extension that provides support for launching haskell-language-server and talking to it, as well as exposing configuration options.

Editors typically 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 on Windows). The exception is VS Code, which can automatically install the binaries if they are not installed already.

VS Code

Install from the VSCode marketplace, or manually from the repository vscode-haskell. The haskell-language-server and haskell-language-server-wrapper binaries will be automatically downloaded on an ad-hoc basis, but if you have them already installed on your PATH then it will just use them instead.

Configuration is done via the “Haskell” section of “Settings”.

Sublime Text

Install LSP using Package Control.

Open Preferences > Package Settings > LSP > Settings and add the following “haskell-language-server” client configuration to the “clients” key:

{
    "clients": {
        "haskell-language-server": {
            "enabled": true,
            "command": ["haskell-language-server-wrapper", "--lsp"],
            "selector": "source.haskell"
        }
    }
}

See the Sublime Text LSP documentation for information on configuring the client. In particular, you can add a “settings” key to the “haskell-language-server” setting to configure specific HLS plugins as described elsewhere in these docs.

Neovim

Neovim provides a native LSP implementation with a Lua framework. Plugins that streamline the setup of haskell-language-server using Neovim’s built-in LSP framework include:

Neovim is also compatible with the Vim plugins.

Vim

You can use Coc, LanguageClient-neovim or any other Vim Language server protocol client. Coc is recommend since it is the only complete LSP implementation for Vim 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.

Minimal Example
{
  "languageserver": {
    "haskell": {
      "command": "haskell-language-server-wrapper",
      "args": ["--lsp"],
      "rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"],
      "filetypes": ["haskell", "lhaskell"]
    }
  }
}
Example with Settings
{
  "languageserver": {
    "haskell": {
      "command": "haskell-language-server-wrapper",
      "args": ["--lsp"],
      "rootPatterns": [ "*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml" ],
      "filetypes": ["haskell", "lhaskell"],
      "settings": {
        "haskell": {
          "checkParents": "CheckOnSave",
          "checkProject": true,
          "maxCompletions": 40,
          "formattingProvider": "ormolu",
          "plugin": {
            "stan": { "globalOn": true }
          }
        }
      }
    }
  }
}
LanguageClient-neovim vim-plug

If you use vim-plug, then you can do this by e.g., including the following line in the Plug section of your init.vim or ~/.vimrc:

Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh'
    \ }

and issuing a :PlugInstall command within Neovim or Vim.

Clone the LanguageClient-neovim repo

As an alternative to using vim-plug shown above, clone LanguageClient-neovim into ~/.vim/pack/XXX/start/, where XXX is just a name for your “plugin suite”.

Configuration and sample ~/.vimrc sections
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:

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 Ctrl+xCtrl+o (<C-x><C-o>) to open up the auto-complete menu, or for asynchronous auto-completion, follow the setup instructions on LanguageClient.

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

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:

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

Further configuration can be done by pointing the g:LanguageClient_settingsPath option variable to the file in which you want to keep your LSP settings.

Atom

Install the two Atom packages atom-ide-ui and haskell,

$ apm install language-haskell atom-ide-ui haskell
Emacs

Emacs support can be provided by different combinations of packages:

or

You can install these manually if you are using plain Emacs; instructions for some specific flavours are included below.

Make sure to check the READMEs of each of these packages, which explain how to configure the various parts of the Emacs integration. In particular, lsp-haskell provides customization options for the haskell-language-server-specific parts, such as the path to the server executable.

use-package eglot

If you are using vanilla emacs with use-package, put the following into your ~/.emacs. This will install eglot and enable it by default in haskell-mode. To configure haskell-language-server we use the eglot-workspace-configuration variable. With M-x eglot-show-workspace-configuration you can see the JSON that eglot will send to haskell-language-server. See https://joaotavora.github.io/eglot/#Customizing-Eglot for more information. As an example, the setting below will disable the stan plugin.

(use-package eglot
  :ensure t
  :config
  (add-hook 'haskell-mode-hook 'eglot-ensure)
  :config
  (setq-default eglot-workspace-configuration
                '((haskell
                   (plugin
                    (stan
                     (globalOn . :json-false))))))  ;; disable stan
  :custom
  (eglot-autoshutdown t)  ;; shutdown language server after closing last file
  (eglot-confirm-server-initiated-edits nil)  ;; allow edits without confirmation
  )
doom-emacs

Manual installation of packages is not required. Enable the lsp module and the haskell lang module with lsp flag in .doom.d/init.el:

:tools
lsp
;; ...
:lang
(haskell +lsp)

then do $HOME/.emacs.d/bin/doom sync

Spacemacs

Manual installation of packages is not required. Enable the haskell layer and the lsp layer in your Spacemacs config file:

dotspacemacs-configuration-layers
  '(
    haskell
    lsp
    ;; ...
  )
Kakoune
  1. Grab a copy of kak-lsp, and follow the setup instructions.

  2. Point your kak-lsp.toml to haskell-language-server-wrapper.

[language.haskell]
filetypes = ["haskell"]
roots = ["Setup.hs", "stack.yaml", "*.cabal"]
command = "haskell-language-server-wrapper"
args = ["--lsp"]
Helix

Once haskell-language-server-wrapper is installed in your system, it will be used automatically by the editor. For more details please refer to the helix guide on installing language servers


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4