haskell / haskell/haskell-language-server

Editor Configuration Documentation improvement

Open
#3,619 7 comments 1 reaction 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

@hasufell @wz1000 As a follow up to discussion on the monthly hls contributers meeting today, I am attempting to lay out some of the issues I have had setting up hls for neovim and some thoughts I have on how the docs could be improved. Appologies if this is a bit longwinded; I am trying to be thorough in documenting my experience.

One idea that stands out to me is that the docs seem to assume that users know how to configure their editor of choice, which I don't think is always a reasonable assumption. In my case, I have previously only used neovim with an extremely minimal configuration and no plugins. I know nothing about lua and how to use it to configure neovim for more complex plugin configuration. As vim/neovim is an editor that can be associated with minimalism, I could imagine that I am not the only person who could find themselves wanting to use hls with neovim and not knowing how to use lua. I could also imagine someone new to haskell trying out more than one new thing at once, and not knowing anything about their editor of choice for the moment. In general I think it would be nice if for as many editors as possible we can include a minimal viable complete configuration for the editor, assuming that the user is coming in with no previous configuration. This should include anything that needs to be installed for the configuration to work (like lua, luarocks, dependency plugins, etc.).

For me specifically, here are the pain points I encountered while getting neovim set up, and the questions I still have. I chose to try [haskell-tools.nvim](https://github.com/MrcJkb/haskell-tools.nvim) first.

- I needed to upgrade my version of neovim, as the apt package is pretty far out of date. I ended up using the [neovim](https://github.com/richin13/asdf-neovim) plugin for [asdf](https://asdf-vm.com/) for this, which worked fine, except that for some reason `~/.asdf/shims` didn't get added to my path when I installed asdf (this likely is related to the fact that I use fish shell).
- I determined that the dependency plugins, both optional and required, were best installed using luarocks, even though none of the READMEs for those plugins suggested luarocks as an install option. In the process of installing these plugins, I ended up installing lua a total of 3 times, also using [asdf](https://github.com/Stratus3D/asdf-lua). This is because the different plugins support different versions of lua. I first installed the latest version, thinking that would be fine. I was pleased that installing lua with asdf also installed luarocks. Then I tried to install [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) and was told by luarocks that it only supports lua 5.1 through 5.3, but not 5.4. I then installed lua 5.3, reinstalled plenary.nvim, and attempted to install [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim). This time, luarocks informed me that telescope.nvim only supports lua 5.1. Finally, I installed lua 5.1.5, reinstalled plenary.nvim, reinstalled telescope.nvim, and installed nvim-dap.
- I had no trouble using cabal and stack to install the haskell executable dependencies for haskell-tools.nvim, [hoogle](https://github.com/ndmitchell/hoogle/blob/master/docs/Install.md), [fast-tags](https://github.com/elaforge/fast-tags), and [haskell-debug-adapter](https://github.com/phoityne/haskell-debug-adapter/). However, I do think that the neovim startup instructions should include the commands to clone these repos and install them using cabal and stack, because I think hls should be accessible to haskell newbies.
- Next I created the file `~/.config/nvim/ftplugin/haskell.lua` and put the recommended quickstart configuration in. Then I attempted to open a haskell file in neovim and encountered a lua error. After a bit of digging I figured out that I needed to set the LUA_PATH environment variable with the location of plugin installations. Those proper installations are part of the output of the `luarocks path` command. Once I set that environment variable I was able to open neovim without encountering lua errors.
- Next I was faced with a cabal error preventing hls from starting. This turned out to be a bug in the latest version of cabal. I don't anticipate most users will encounter this sort of problem if they stick to the ghcup recommended version of cabal-install, which I was not.
- Now I was finally at the point where I could attempt to use some of the functionality of hls in neovim. So far I have successfully used gotoDefinition and not much else. I am not entirely clear on what all I did to get this working. I still have some questions about the configuration. First, from this line in the haskell-tools.nvim quickstart:
```
For more LSP related keymaps, [see the nvim-lspconfig suggestions](https://github.com/neovim/nvim-lspconfig#suggested-configuration).
```
it's not clear to me if haskell-tools.nvim reimplements those keymaps by default and the link is simply for reference, or if the user needs to add those keymaps to their config in addition to the haskell-tools.nvim quickstart. I currently have the second option in my config, so I installed [nvim-lspconfig](nvim-lspconfig) (again, not sure if this is redundant with haskell-tools.nvim) and the following is the contents of my `~/.config/nvim/ftplugin/haskell.lua`:
```
local ht = require('haskell-tools')
local def_opts = { noremap = true, silent = true, }
ht.start_or_attach {
hls = {
on_attach = function(client, bufnr)
local opts = vim.tbl_extend('keep', def_opts, { buffer = bufnr, })
-- haskell-language-server relies heavily on codeLenses,
-- so auto-refresh (see advanced configuration) is enabled by default
vim.keymap.set('n', 'ca', vim.lsp.codelens.run, opts)
vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts)
vim.keymap.set('n', 'ea', ht.lsp.buf_eval_all, opts)

--copied from https://github.com/neovim/nvim-lspconfig#suggested-configuration
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', 'wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', 'f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
},
}

-- Suggested keymaps that do not depend on haskell-language-server:
local bufnr = vim.api.nvim_get_current_buf()
-- set buffer = bufnr in ftplugin/haskell.lua
local opts = { noremap = true, silent = true, buffer = bufnr }

-- Toggle a GHCi repl for the current package
vim.keymap.set('n', 'rr', ht.repl.toggle, opts)
-- Toggle a GHCi repl for the current buffer
vim.keymap.set('n', 'rf', function()
ht.repl.toggle(vim.api.nvim_buf_get_name(0))
end, def_opts)
vim.keymap.set('n', 'rq', ht.repl.quit, opts)

-- Detect nvim-dap launch configurations
-- (requires nvim-dap and haskell-debug-adapter)
ht.dap.discover_configurations(bufnr)
```
- My current problem is that I really have no idea how to modify my config or see what my config is dynamically. Looking into lua a bit it seems that there isn't a nice general way to print a lua table, which seems to be the data structure of the configuration. Most relevant for the work I will be doing on goto definition, I would like to change what the default hls command so that I can use a custom script (@wz1000 helped me set up a custom script yesterday and I got it working for vscode but not neovim).

I think the current docs are likely fine for people who already use lua for configuration, so the upgrade to the docs I would suggest is having two sections under neovim. One would be basically what we have now, for people who already use a complex neovim configuration, and under it the more detailed instructions. Next I plan to make a pull request adding those more detailed instructions based on my experiences as documented above.

It would be great if every editor could have both of these options, but I don't know if I am prepared to flesh all of them out at this time. I understand if some people think this might be outside of the scope of what hls docs should provide, but I personally think that one of the main goals of an ide should be beginner friendliness. Towards this end I think excruciatingly detailed docs are a good idea.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.