haskell / haskell-language-server

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

hie-core: Vim integration #1138

Closed madgen closed 3 years ago

madgen commented 5 years ago

I installed hie-core and it works from command line on a given file. I also installed vim-lsp to integrate with neovim and added the configuration line from the README in my init.vim, but when I try :LspHover on a symbol, I get Retrieving hover not supported for haskell. What do I do next?

ndmitchell commented 5 years ago

If you are at MuniHac, come over and talk to me in person!

madgen commented 5 years ago

@ndmitchell I'm not, but your keynote was great. Thanks for putting it on your website so quickly!

ndmitchell commented 5 years ago

@smatting got it working on Vim and wrote the instructions, perhaps he has some ideas?

smatting commented 5 years ago

@madgen I get the same error message on the first run of :LspHover until the server has completed starting in the background. Other things I can think of:

ghost commented 5 years ago

Hey, @madgen. I have it working with neovim and https://github.com/neoclide/coc.nvim. Here's my coc config (for haskell, daml, scala). You will have to change the "command", and possibly "args" for hie-core since I have one that is adapted for DA's daml repo.

{
  "languageserver": {
    "haskell": {
      "command": "/home/drsk/daml/compiler/hie-core/hie-core-daml.sh",
      "args": [
        "--lsp"
      ],
      "rootPatterns": [
        ".stack.yaml",
        ".hie-bios",
        "BUILD.bazel",
        "cabal.config",
        "package.yaml"
      ],
      "filetypes": [
        "hs",
        "lhs",
        "haskell"
      ],
      "initializationOptions": {
        "languageServerHaskell": {
          "hlintOn": true,
          "maxNumberOfProblems": 10,
          "completionSnippetsOn": true
        }
      }
    },
    "daml": {
      "command": "daml-head",
      "args": [
        "ide"
      ],
      "rootPatterns": [
        "daml.yaml"
      ],
      "filetypes": [
        "daml"
      ],
      "initializationOptions": {}
    },
    "metals": {
      "command": "metals-vim",
      "rootPatterns": [
        "build.sbt",
        "BUILD.bazel"
      ],
      "filetypes": [
        "scala",
        "sbt"
      ]
    }
  }
}
smatting commented 5 years ago

@robin-da Thanks for sharing! Maybe we should recommend coc.nvim over vim-lsp in the README? It seems it has more features, e.g. :CocList diagnostics. Do you know how you can view the error message in full instead of just a single line? I wasn't able to figure this out yet

ghost commented 5 years ago

@smatting [c will show you the next error. Yes, I think we should change it, coc.nvim seems more mature and supports most of the vscode features, it's really nice so far.

ghost commented 5 years ago

you might also want to put this in your init.vim:


"
" if hidden is not set, TextEdit might fail.
set hidden

" Some servers have issues with backup files, see digital-asset/daml#649
set nobackup
set nowritebackup

" Better display for messages
set cmdheight=2

" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300

" don't give |ins-completion-menu| messages.
set shortmess+=c

" always show signcolumns
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"

" Use `[c` and `]c` to navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)

" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  else
    call CocAction('doHover')
  endif
endfunction

" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')

" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)

" Remap for format selected region
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)
madgen commented 5 years ago

So changing over to coc.nvim over vim-lsp and restarting the computer worked(ish). Now when I type something and it causes an error, I get one-liner errors and an indication on the left side of my screen. But I have no idea how the rest of the features work. CocAction does not list any options and the commands under CocCommand does not do anything. extensions under CocList is also empty.

maralorn commented 5 years ago
      "initializationOptions": {
        "languageServerHaskell": {
          "hlintOn": true,
          "maxNumberOfProblems": 10,
          "completionSnippetsOn": true
        }
      }
    },

I may be wrong, but arn‘t these options from the usage wih hie-wrapper as seen for example here: http://marco-lopes.com/articles/Vim-and-Haskell-in-2019/ ?

If yes that part of the config should probably be removed from the README. Also right now I am missing hlint, warnings and completions with coc + ghcide. Only errors work.

ndmitchell commented 5 years ago

HLint and completions aren't (yet) features of ghcide. Warnings should be there, but you may want to turn on certain warnings.

maralorn commented 5 years ago

Thanks for the explanation! I made a pull request for the config.

Is there a good channel to ask for problems with setup, which are probably not bugs?

ndmitchell commented 4 years ago

There seem to be a lot of Vim installation instructions at https://github.com/digital-asset/ghcide#using-with-vimneovim. If none of them are sufficient please send a patch.

My guess is 90% of issues are setup issues. I think we'll just treat them like normal bugs for now.