Type-at-point ocaml-lsp/merlin in vim/neovim


I’d like to know whether ocaml-lsp supports type-at-point feature? The point is to display to the user the type at point inferred by the compiler.
I think this functionality already exists in Merlin for a while: merlin-show-type-at-point, and I’ve read articles talking about people’s corresponding lsp-mode/merlin Emacs config.
How about VIM? Is it integrated in ocaml-lsp already? From looking on GitHub, it seems it’s not, but then how come people manage to integrate it in Emacs’ lsp-mode?


I am using neovim and the following config:

in .vimrc

Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'branch': 'release'}

nnoremap <silent> gh :call <SID>show_documentation()<CR>

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

and in :CocConfig:

    "ocaml": {
      "command": "ocamllsp",
      "rootPatterns": ["dune-project"],
      "filetypes": ["ocaml"],
      "initializationOptions": {},
      "settings": {}

which allows to show a type tooltip like this when you press gh

1 Like

In my .config/nvim/init.vim I have the default things setup by opam and then (amongst other things):

autocmd FileType ocaml nnoremap <LocalLeader>t :MerlinTypeOf<CR>

Thanks for your reply. I see that you use merlin directly in vim. I rely on a LSP client for all the languages I write code in (coc.nvim at the moment) and was using ocaml-lsp for OCaml. Merlin is a dependency of ocaml-lsp.
I guess I’ll just ditch LSP for now and opt for merlin directly.

Sorry, I had missed your message.
Indeed, I was using the exact same configuration, but did not realize ‘show_documentation()’ does show type inference… I feel silly. My bad!
Good to know I can still rely on LSP.