ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.59k stars 233 forks source link

Failed to load merlin in vim #773

Open mdesharnais opened 6 years ago

mdesharnais commented 6 years ago

After installing merlin:

$ opam list --installed | grep -F merlin
merlin              3.0.5  Editor helper, provides completion, typing and source

I configured vim with:

$ opam user-setup install
ocamltop > base > .ocamlinit: up to date
vim > .vimrc: already exists, not installing base template
vim > base > .vimrc: up to date

And get this error message when opening a file with vim:

":merlin-log:" [New File]
Error detected while processing function merlin#Register[133]..merlin#LoadProject:
line    2:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/MDS7/.opam/4.06.0/share/merlin/vim/autoload/merlin.py", line 730, in setup_merlin
    result = command("check-configuration")
  File "/home/MDS7/.opam/4.06.0/share/merlin/vim/autoload/merlin.py", line 188, in command
    return command2(args)
  File "/home/MDS7/.opam/4.06.0/share/merlin/vim/autoload/merlin.py", line 181, in command2
    raise Failure(value)
merlin.Failure: u'abnormal termination'
Press ENTER or type command to continue

My .vimrc is:

set number
set tabstop=2 shiftwidth=2 softtabstop=0 expandtab smarttab
set smartindent
set listchars=trail:¤,nbsp:~,tab:>-
set list
set ignorecase
set smartcase
" ## added by OPAM user-setup for vim / base ## 93ee63e278bdfc07d1139a748ed3fff2 ## you can edit, but keep this line
let s:opam_share_dir = system("opam config var share")
let s:opam_share_dir = substitute(s:opam_share_dir, '[\r\n]*$', '', '')

let s:opam_configuration = {}

function! OpamConfOcpIndent()
  execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')

function! OpamConfOcpIndex()
  execute "set rtp+=" . s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')

function! OpamConfMerlin()
  let l:dir = s:opam_share_dir . "/merlin/vim"
  execute "set rtp+=" . l:dir
endfunction
let s:opam_configuration['merlin'] = function('OpamConfMerlin')

let s:opam_packages = ["ocp-indent", "ocp-index", "merlin"]
let s:opam_check_cmdline = ["opam list --installed --short --safe --color=never"] + s:opam_packages
let s:opam_available_tools = split(system(join(s:opam_check_cmdline)))
for tool in s:opam_packages
  " Respect package order (merlin should be after ocp-index)
  if count(s:opam_available_tools, tool) > 0
    call s:opam_configuration[tool]()
  endif
endfor
" ## end of OPAM user-setup addition for vim / base ## keep this line
ArchangeGabriel commented 6 years ago

Same issue here, with a much simpler .vimrc:

filetype plugin indent on
syntax on
set number
set nocompatible
set wildmenu
set wrapscan
set tabstop=4
set expandtab
set shiftwidth=4
set breakindent
set smartindent
set nojoinspaces
ArchangeGabriel commented 6 years ago

My exact log:

Error detected while processing function merlin#Register[133]..merlin#LoadProject:
line    2:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/share/vim/vimfiles/autoload/merlin.py", line 730, in setup_merlin
    result = command("check-configuration")
  File "/usr/share/vim/vimfiles/autoload/merlin.py", line 188, in command
    return command2(args)
  File "/usr/share/vim/vimfiles/autoload/merlin.py", line 181, in command2
    raise Failure(value)
merlin.Failure: u'abnormal termination'
cyr-l commented 6 years ago

I don't know if you managed to resolve your issue but this could come from the fact that you're not using the required OCaml version (version 4.02.3 at the time of writing).

ArchangeGabriel commented 6 years ago

I’m using 4.06.0. But following the doc you’ve pointed, I’ve got interesting results running ocamlmerlin -version:

Fatal error: exception Failure("Config file not found - neither /etc/findlib.conf nor the directory /etc/findlib.conf.d")
ArchangeGabriel commented 6 years ago

Prefixing with OCAMLFIND_CONF=/dev/null as advised in https://github.com/ocaml/merlin/issues/551 returned:

The Merlin toolkit version 3.0.5, for Ocaml 4.06.0

As a matter of fact, prepending this var to running vim works. So looks that was the issue, not sure why and what would be the best way to deal with it.

ArchangeGabriel commented 6 years ago

Apparently this is because there is no ocaml-findlib on my system.