neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.47k stars 118 forks source link

UpdateRemotePlugins not finding any specs #564

Closed tanj closed 2 months ago

tanj commented 2 months ago

I'm trying to figure out why UpdateRemotePlugins is not finding any plugins. I hacked in some printf debugging into runtime/autoload/remote/host.vim and it seems like when function! s:RegistrationCommands calls rpcrequest(channel, 'specs', path) it doesn't seem to come back with any specs.

paths: ['C:/Users/<user>/AppData/Local/nvim/rplugin/python3/__pycache__',
'C:/Users/<user>/AppData/Local/nvim/rplugin/python3/example.py',
'C:/Users/<user>/AppData/Local/nvim/rplugin/python3/limit.py']
no spec found: 0 
no spec found: 0 
no spec found: 0 
remote/host: python3 host registered plugins [] 
remote/host: generated rplugin manifest: C:\Users\<user>\AppData\Local\nvim-data/rplugin.vim 

Modified function for my printf debug

function! s:RegistrationCommands(host) abort
  " Register a temporary host clone for discovering specs
  let host_id = a:host.'-registration-clone'
  call remote#host#RegisterClone(host_id, a:host)
  let pattern = s:plugin_patterns[a:host]
  let paths = nvim_get_runtime_file('rplugin/'.a:host.'/'.pattern, 1)
  let paths = map(paths, 'tr(resolve(v:val),"\\","/")') " Normalize slashes #4795
  let paths = uniq(sort(paths))
  if empty(paths)
    return []
  endif

  for path in paths
    call remote#host#RegisterPlugin(host_id, path, [])
  endfor
  let channel = remote#host#Require(host_id)
  let lines = []
  let registered = []
  echomsg printf("paths: %s", paths)
  for path in paths
    unlet! specs
    let specs = rpcrequest(channel, 'specs', path)
    if type(specs) != type([])
      " host didn't return a spec list, indicates a failure while loading a
      " plugin
      echomsg printf("no spec found: %s", specs)
      continue
    endif
    echomsg printf("found spec: %s", specs)
    call add(lines, "call remote#host#RegisterPlugin('".a:host
          \ ."', '".path."', [")
    for spec in specs
      call add(lines, "      \\ ".string(spec).",")
    endfor
    call add(lines, "     \\ ])")
    call add(registered, path)
  endfor
  echomsg printf("remote/host: %s host registered plugins %s",
        \ a:host, string(map(registered, "fnamemodify(v:val, ':t')")))

  " Delete the temporary host clone
  call jobstop(s:hosts[host_id].channel)
  call remove(s:hosts, host_id)
  call remove(s:plugins_for_host, host_id)
  return lines
endfunction

Neovim version

% nvim --version
NVIM v0.10.0-dev-2830+g541c2d381
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188

OS

Windows 11 Pro

tanj commented 2 months ago

I did some digging with adding some log spam and I think the issue is that we have a mix of windows path separators and posix path separators.

2024-04-13 08:52:57,652 [INFO @ host.py:start:82] 27388 - Start host ['C:/Users/<user>/AppData/Local/nvim/rplugin/python3/example.py', 'C:/Users/jtebokkel/AppData/Local/nvim/rplugin/python3/limit.py']
2024-04-13 08:52:57,652 [DEBUG @ session.py:run:170] 27388 - Checking if we have setup callback...
2024-04-13 08:52:57,652 [DEBUG @ session.py:run:172] 27388 - Starting greenlet for on_setup
2024-04-13 08:52:57,653 [INFO @ host.py:_discover_functions:232] 27388 - Discovering functions... C:\Users\<user>\AppData\Local\nvim\rplugin\python3\example.py
2024-04-13 08:52:57,653 [INFO @ host.py:_discover_functions:237] 27388 - discover function: <function TestPlugin.on_bufenter at 0x000001F5F6406980>
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:268] 27388 - <function TestPlugin.on_bufenter at 0x000001F5F6406980> has spec: {'type': 'autocmd', 'name': 'BufEnter', 'sync': True, 'opts': {'pattern': '*.py', 'eval': 'expand("<afile>")'}}
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:237] 27388 - discover function: <function TestPlugin.testcommand at 0x000001F5F64068E0>
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:268] 27388 - <function TestPlugin.testcommand at 0x000001F5F64068E0> has spec: {'type': 'command', 'name': 'TestCommand', 'sync': False, 'opts': {'range': '', 'nargs': '*'}}
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:237] 27388 - discover function: <function TestPlugin.testfunction at 0x000001F5F6406840>
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:268] 27388 - <function TestPlugin.testfunction at 0x000001F5F6406840> has spec: {'type': 'function', 'name': 'TestFunction', 'sync': True, 'opts': {}}
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:274] 27388 - specs collected: [{'type': 'autocmd', 'name': 'BufEnter', 'sync': True, 'opts': {'pattern': '*.py', 'eval': 'expand("<afile>")'}}, {'type': 'command', 'name': 'TestCommand', 'sync': False, 'opts': {'range': '', 'nargs': '*'}}, {'type': 'function', 'name': 'TestFunction', 'sync': True, 'opts': {}}]
2024-04-13 08:52:57,654 [INFO @ host.py:_discover_functions:277] 27388 - self._specs: {'C:\\Users\\<user>\\AppData\\Local\\nvim\\rplugin\\python3\\example.py': [{'type': 'autocmd', 'name': 'BufEnter', 'sync': True, 'opts': {'pattern': '*.py', 'eval': 'expand("<afile>")'}}, {'type': 'command', 'name': 'TestCommand', 'sync': False, 'opts': {'range': '', 'nargs': '*'}}, {'type': 'function', 'name': 'TestFunction', 'sync': True, 'opts': {}}]}

added one more debug log and confirm issue

2024-04-13 09:06:09,989 [INFO @ host.py:_on_specs_request:287] 34876 - on_specs_request path: 'C:/Users/<user>/AppData/Local/nvim/rplugin/python3/example.py'

we are adding the specs with path = os.path.normpath(path) and looking them up with no change in path.

This was introduced in f24459755da9e42ec3284fe80c7241ee05fa38ae