haskell / haskell-language-server

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

Insert function signature on neovim #2273

Closed andregpss closed 3 years ago

andregpss commented 3 years ago

Your environment

haskell-language-server version: 1.4.0.0 (GHC: 8.10.4) (PATH: C:\hls\haskell-language-server-wrapper.exe) (GIT hash: 253547816ee216c53ee7dacc0ad3cac43e863d30)
Tool versions found on the $PATH
cabal:          2.4.1.0
stack:          2.5.1
ghc:            8.6.5

Which OS do you use: Windows 11 Which lsp-client do you use: Neovim v0.4.3

Question

How can i insert the signature of a function on neovim? When i use 'K' coc command for viewing the function documentation, it shows the function signature. What command should i use to insert that signature on the code? Doing this on Visual Studio Code is easy because it suggests doing it, and i must only click on the proposed signature. But i do not know how to do it on neovim.

eddiemundo commented 3 years ago

If you use CoC, then bind coc-codelens-action and that command will insert the inferred type signature of something at the top-level.

I noticed you can also do :: _ and use coc-codeaction on the underscore and get the option to fill it in too.

andregpss commented 3 years ago

Thanks @eddiemundo Both solutions worked for me (after some research :-)) On first solution, i added the following code to my vim.rc file:

vmap <leader>p  <Plug>(coc-codelens-action)
nmap <leader>p  <Plug>(coc-codelens-action)

On last solution, i added a fake signature like myFunction :: _, selected the _ character and then pressed \a.

Two additional questions: is there a command to apply the codelens actions on the selected code? and a command to navigate on the codelens actions?

eddiemundo commented 3 years ago

I don't know of any way of applying code lens actions to a selection, or a way of navigating to them. I guess that could be a feature request...

You can navigate to places with a type signature hole (among other things) using <plug>(coc-diagnostic-next) and <plug>(coc-diagnostic-prev) but that's probably not what you're looking for.

The rest of the commands can be found https://github.com/neoclide/coc.nvim/blob/master/doc/coc.txt , or :h cocnvim if you haven't found that already.

andregpss commented 3 years ago

I also set "codeLens.enable": true on Coc configuration file so it is possible to view code lens suggestions.