merlin icon indicating copy to clipboard operation
merlin copied to clipboard

Not working with neovim and Nix: Key not present in Dictionary: "oca mlmerlin_path"

Open glyh opened this issue 11 months ago • 1 comments

Since NixOS is not a standard setup, I expect this to have rough edges.

What I have: nvim/after/ftplugin/ocaml.lua

-- Function to get the Merlin share path
local function get_merlin_share_path()
  -- Find the path of `ocamlmerlin` using `vim.fn.exepath()`
  local merlin_exe = vim.fn.exepath "ocamlmerlin"
  if merlin_exe == "" then
    return nil
  end

  -- Get the directory containing `ocamlmerlin`
  local merlin_dir = vim.fn.fnamemodify(merlin_exe, ":h")

  -- Return the share path relative to the executable
  return merlin_dir .. "/../share"
end

-- Get the opam share path
local opamshare = get_merlin_share_path()

-- If the share path is found, append it to the runtime path
if opamshare then
  vim.opt.runtimepath:append(opamshare .. "/merlin/vim")
end

In init.lua

local enable_providers = {
  "python3_provider",
  -- and so on
}

for _, plugin in pairs(enable_providers) do
  vim.g["loaded_" .. plugin] = nil
  vim.cmd("runtime " .. plugin)
end

In checkhealth I'm sure pynvim is present. But I'm still getting this:

E5108: Error executing lua Vim:Error invoking 'python_execute' on channel 3 (python3-script-host):                                      
Traceback (most recent call last):                                                                                                      
  File "<string>", line 1, in <module>                                                                                                  
  File "/nix/store/ldn715jjd4jg4mypi125ha4v8spaklnv-merlin-4.5-414/share/merlin/vim/autoload/merlin.py", line 887, in setup_merlin      
    result = command("check-configuration")                                                                                             
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                             
  File "/nix/store/ldn715jjd4jg4mypi125ha4v8spaklnv-merlin-4.5-414/share/merlin/vim/autoload/merlin.py", line 189, in command           
    return command2(args)                                                                                                               
           ^^^^^^^^^^^^^^                                                                                                               
  File "/nix/store/ldn715jjd4jg4mypi125ha4v8spaklnv-merlin-4.5-414/share/merlin/vim/autoload/merlin.py", line 173, in command2          
    result = json.loads(merlin_exec(cmdline,input=content))                                                                             
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                              
  File "/nix/store/ldn715jjd4jg4mypi125ha4v8spaklnv-merlin-4.5-414/share/merlin/vim/autoload/merlin.py", line 99, in merlin_exec        
    path = vim.eval("merlin#SelectBinary()")                                                                                            
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                            
  File "/nix/store/62cdsp8a4mxqd28fqakfvpfijcacn9sz-python3.11-pynvim-0.4.3/lib/python3.11/site-packages/pynvim/plugin/script_host.py", 
line 205, in eval                                                                                                                       
    obj = self.request("vim_eval", expr)                                                                                                
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                
  File "/nix/store/62cdsp8a4mxqd28fqakfvpfijcacn9sz-python3.11-pynvim-0.4.3/lib/python3.11/site-packages/pynvim/api/nvim.py", line 182, 
in request                                                                                                                              
    res = self._session.request(name, *args, **kwargs)                                                                                  
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
  File "/nix/store/62cdsp8a4mxqd28fqakfvpfijcacn9sz-python3.11-pynvim-0.4.3/lib/python3.11/site-packages/pynvim/msgpack_rpc/session.py",
 line 102, in request                                                                                                                   
    raise self.error_wrapper(err)                                                                                                       
pynvim.api.common.NvimError: FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[20]..script /nix/store/ldn715jjd4jg4mypi125ha4v
8spaklnv-merlin-4.5-414/share/merlin/vim/ftplugin/ocaml.vim[2]..function merlin#Register[147]..merlin#LoadProject[2]..provider#python3#C
all[1]..merlin#LoadProject[2]..merlin#SelectBinary[8]..merlin#FindBinary, line 13: Vim(return):E716: Key not present in Dictionary: "oca
mlmerlin_path"                                                                                                                          
stack traceback:                                                                                                                        
        [C]: at 0x5555556ea469                                                                                                          
        [C]: in function 'nvim_exec_autocmds'                                                                                           
        ...yh/.local/share/nvim/lazy/NvChad/lua/nvchad/autocmds.lua:19: in function <...yh/.local/share/nvim/lazy/NvChad/lua/nvchad/auto
cmds.lua:18> 

glyh avatar Mar 26 '25 08:03 glyh

Maybe @Julow ?

voodoos avatar Mar 26 '25 13:03 voodoos