haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.66k stars 355 forks source link

Editor Configuration Documentation improvement #3619

Open nlander opened 1 year ago

nlander commented 1 year ago

@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 first.

-- 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.
nlander commented 1 year ago

I'm going to add more of my experiences trying out some hls features in neovim here. I'm hoping to learn enough about the correct way to use these features that I can add some documentation about them to #3620.

nlander commented 1 year ago

Neovim seems to be adding explicit versions of the non-explicit imports, but they are truncated and I don't seem to be able to move my cursor into them or scroll to the right to see the rest of the explicit imports.

nlander commented 1 year ago

Some things I'm noticing playing around with K for hover actions: It's working fine most places except I am getting a lua error when I press K on the closing parenthesis of the functions imported in an import statement. This is the error:

Error executing vim.schedule lua callback: .../lua/5.1.5/luarocks/share/lua/5.1/haskell-tools/util.lua:68: inva
lid pattern capture
stack traceback:
        [C]: in function 'match'
        .../lua/5.1.5/luarocks/share/lua/5.1/haskell-tools/util.lua:68: in function 'try_get_signature_from_mar
kdown'
        ...5.1.5/luarocks/share/lua/5.1/haskell-tools/lsp/hover.lua:119: in function 'handler'
        ...installs/neovim/0.9.0/share/nvim/runtime/lua/vim/lsp.lua:1394: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I wonder if this is a bug I should report in the haskell-tools.nvim repo, or if it is something that can be fixed in my config.

The other thing I'm wondering is how to enter the hover actions without using the mouse. If I click into the box that comes up with my mouse, then I am able to navigate it as usual with jkhl, and pressing on one of the numbered options takes that action. Is there any way I can enter and exit the hover box without using the mouse? Not needing to use the mouse is a big part of why I like to use neovim, and it seems like the whole point of having the hover action bound to a key is also to avoid using the mouse.

nlander commented 1 year ago

I'm trying out gotoDefinition and gotoTypeDefinition. gotoDefinition seems to be working with the keybinding gd, but gotoTypeDefinition is not working with the keybinding <space>D. gotoTypeDefintion is working from the hover menu, however.

nlander commented 1 year ago

I closed the PR because after discussing with @wz1000 it seems that beginner-friendly setup instructions shouldn't use haskell-tools.nvim.

michaelpj commented 1 year ago

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.

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.

Personally, I think our answer to that should be "use VSCode". It has the most plug-and-play setup, and I'm not sure we can realistically support detailed configuration for every editor and we have to rely on some user knowledge. Especially since Emacs and vim are configured in fully fledged programming languages, and have varied and frequently-changing configuration management systems...

For me specifically, here are the pain points I encountered while getting neovim set up

This is exactly why I don't think we can really support this. This is a big list of editor specific stuff which we are unlikely to be able to keep current or even verify. It probably varies by OS also!

michaelpj commented 1 year ago

We discussed this a bit in our meeting. HLS is a first port of call for many people getting started, so it would be nice to provide something for such people. If VSCode is the smoothest path, then we should have a prominent "Getting started" page that says something like "For a smooth setup, use GHCup and VSCode".

Maybe we can also provide these detailed instructions on a best-effort basis, but we should clearly mark them as such and warn that they may not work/be out of date.