numirias / semshi

🌈 Semantic Highlighting for Python in Neovim
1.02k stars 33 forks source link

Error detected while processing function remote#define#request: #11

Open balta2ar opened 6 years ago

balta2ar commented 6 years ago

Hi! I get this when I start neovim (0.2.2) and the latest semshi:

Error detected while processing function remote#define#request:                                                                                                                                
line    2:                                                                                                                                                                                     
no request handler registered for "/home/bz/rc.arch/bz/.vim/plugged/semshi/rplugin/python3/semshi:autocmd:BufEnter:*.py"

And then this:

error caught in async handler '/home/bz/rc.arch/bz/.vim/plugged/semshi/rplugin/python3/semshi:autocmd:CursorMoved:*.py []'                                                                     
Traceback (most recent call last):                                                                                                                                                             
  File "/home/bz/rc.arch/bz/.vim/plugged/semshi/rplugin/python3/semshi/plugin.py", line 13, in wrapper                                                                                         
    if not self._options.active: # pylint: disable=protected-access                                                                                                                            
AttributeError: 'NoneType' object has no attribute 'active'
numirias commented 6 years ago

Thanks for reporting! This seems to be caused by a similar initialization bug as #10.

Do you mind sharing which OS and neovim frontend you are using?

balta2ar commented 6 years ago

I'm using ArchLinux and plain neovim without any frontends.

numirias commented 6 years ago

Odd, I'm using the exact same setup and don't experience the bug.

balta2ar commented 6 years ago

It boiled down to this. I can't minimize it any further. If I remove LanguageClient or far, the error goes away:

set rtp+=~/.fzf

if &compatible
  set nocompatible
endif

call plug#begin('~/.vim/plugged')

Plug 'numirias/semshi'

Plug 'autozimu/LanguageClient-neovim'
Plug 'brooth/far.vim'

call plug#end()

Did you run :UpdateRemotePlugins

Sure. I ran this command when I was bisecting my vimrc as well. (reduce vimrc, start neovim to update remote plugins, start neovim again to check).

numirias commented 6 years ago

I couldn't reproduce the bug with your config. There seems to be some race condition during initialization.

However, I modified initialization (83f56bfac9debd3c29ef7a9630b57e32d43e5f63) so that Semshi doesn't assume a particular event order anymore. Does that solve the problem for you?

balta2ar commented 6 years ago

Thank you! It helped!

On a side note (and sorry for putting all requests into the same issue), would it possible to have:

  1. an option to start vim with semshi disabled by default (I'd like to turn it on occasionally when I read specific pieces of code).
  2. have toggle command. I know it's easy to implement it yourself, but it's convenient to have it out of the box.
numirias commented 6 years ago

Thanks for your help resolving this bug!

  1. You can set let g:semshi#excluded_buffers = ['*'] to initially disable Semshi on all buffers.
  2. I implemented :Semshi toggle.

Does that enable the workflow you had in mind?

balta2ar commented 6 years ago

Thank you! It's very helpful and convenient now!

Looks like I was a bit hasty and for some reason I'm still seeing the first message at startup after your recent update:

Error detected while processing function remote#define#request:
line    2:
no request handler registered for "/home/bz/rc.arch/bz/.vim/plugged/semshi/rplugin/python3/semshi:autocmd:BufEnter:*.py"

Though I don't see the second message anymore (well, at least some good news). However, even though this message is printed, the plugin seems to be working fine (I'm still testing using the minimal configuration above plus the options that you've mentioned). Is there any other information I can provide to help you find the reason of that first message?

EDIT: okay, I've just realized that I wrote previous message from my working machine and now I'm testing at home machine.

EDIT2: looks like there are more race conditions and not necessarily in this plugin. Sometimes I notice that the error is gone with my full vimrc, other times I see this:

Error detected while processing function <SNR>82_on_bufenter[13]..gitgutter#process_buffer[8]..gitgutter#diff#run_diff:                                           
line    2:                                                                                                                                                        
no notification handler registered for "/home/bz/rc.arch/bz/.vim/plugged/LanguageClient-neovim/rplugin/python3/LanguageClient:autocmd:BufReadPost:*"              
Error detected while processing function <SNR>82_on_bufenter:                                                                                                     
line   13:                                                                                                                                                        
E171: Missing :endif

Side note: is it expected that only other instances are highlighted, not the one under the cursor?

numirias commented 6 years ago

I'm sorry you're still having issues.

Does the no request handler registered message appear all the time (on that machine)? Is there a configuration where it does not appear?

It's odd because the message indicates that the BufEnter event handler isn't registered which is just done through a Python decorator, no fancy application logic. E.g., I could provoke the error by going into semshi/plugin.py and commenting out the @neovim.autocmd('BufEnter' ...) decorator (without running :UpdateRemotePlugins again).

So it appears like neovim doesn't register the plugin's handlers in time to handle the event. Given that you also got

no notification handler registered for "/home/bz/rc.arch/bz/.vim/plugged/LanguageClient-neovim/rplugin/python3/LanguageClient:autocmd:BufReadPost:*"

which is related to a different Python 3 plugin, could this be a bug in the neovim Python client? (Or do you only get any of those errors when you use it in conjunction with Semshi?)

Side note: is it expected that only other instances are highlighted, not the one under the cursor?

I thought about that one. :) You can set the option g:semshi#mark_selected_nodes = 2 to mark the node under the cursor too.

balta2ar commented 6 years ago

I'm sorry you're still having issues.

No worries! I appreciate very much your desire to help and the effort you put into sorting things out!

Does the no request handler registered message appear all the time (on that machine)? Is there a configuration where it does not appear?

Hmm, it looks like yes, all the time when Semshi is on. I think it didn't appear either when I forgot to run :UpdateRemovePlugins since one of the previous config changes, or when I removed one of those plugins that require that command to work (see below).

Or do you only get any of those errors when you use it in conjunction with Semshi?

That is correct. Only after installing Semshi I started to see these messages. Never seen 'em before.

could this be a bug in the neovim Python client?

Is there anything I can do to validate this hypothesis? Maybe it surfaces itself only after a certain number of plugins that rely on UpdateRemotePlugins command?

Anyway, here is my list of such plugins (I think), maybe you could try different combinations of them and see whether the error shows up:

set rtp+=~/.fzf

if &compatible
  set nocompatible
endif

call plug#begin('~/.vim/plugged')

Plug 'numirias/semshi'

Plug 'autozimu/LanguageClient-neovim'
Plug 'brooth/far.vim'
Plug 'raghur/vim-ghost', {'do': ':GhostInstall'}
Plug 'arakashic/chromatica.nvim'
Plug 'Shougo/deoplete.nvim'

call plug#end()

"let mapleader=","
"let g:semshi#excluded_buffers = ['*']
"nnoremap <Leader>z :Semshi toggle<cr>

let g:semshi#mark_selected_nodes = 2

And also here is my complete vimrc: https://gist.github.com/balta2ar/71abb871416bb771b6259223c464e67b Sorry, it's a huge mess, but if it helps you reproduce the problem, it would be a great start.

BTW, since the original message neovim has been released, so I'm on 0.3.0 version now.

numirias commented 6 years ago

Great, I can now repro with your minimal config and exactly these three plugins:

call plug#begin('~/.vim/plugged')
Plug 'numirias/semshi'
Plug 'autozimu/LanguageClient-neovim'
Plug 'brooth/far.vim'
call plug#end()

All three share in common that they are Python 3 plugins and I observed that removing any single one of them stops the error.

I also created a dummy plugin (~/dummy/rplugin/python3/dummy/__init__.py):

import neovim

@neovim.plugin
class Plugin:

    def __init__(self, vim):
        self._vim = vim

    @neovim.autocmd('BufEnter', pattern='*', sync=True)
    def foo(self):
        self._vim.out_write('hey\n')

(You'd load this via e.g. Plug '~/dummy'.)

Enabling that plugin instead of Semshi shows the exact same behavior (again, unless you disable one of the others):

no request handler registered for "/home/me/dummy/rplugin/python3/dummy:autocmd:BufEnter:*"

To me this indeed hints at a problem on Neovim's side.

numirias commented 6 years ago

@balta2ar Unless you think this can be fixed in Semshi, I'd go ahead and file a bug at neovim/python-client.

balta2ar commented 6 years ago

Sure! Do you mind leaving this open to keep the paper trail until there is more information on the issue?

lkhphuc commented 6 years ago

Just want to share that I have the same issue:

Error detected while processing function remote#define#notify
E475: Invalid argument: Chanel doesn't exist

I use the same neovim, tmux, zsh config for my local Mac and Linux remote machines, I only have this issue running on my MacOS Mojave. The softwares on my Mac are always the latest though, while the Linux machines are not as updated.

numirias commented 6 years ago

@lkhphuc Thanks for noting. Are you using Neovim in the terminal, or a particular frontend? Do you get the error consistently or just sometimes?

I still think this may be caused by a race condition in the Neovim Python client. If you like to help get it resolved, you might want to add you thoughts to neovim/python-client#341. In particular, it would be interesting to see if you can reproduce the error with the methods I described there (which would also show that the bug can be triggered without Semshi).

lkhphuc commented 5 years ago

Sorry for late reply.

Are you using Neovim in the terminal, or a particular frontend? Do you get the error consistently or just sometimes?

I use Neovim on Therm terminal (a minimal fork of iTerm 2), and it happens every time I start typing in a python file and it will not stop until I quit neovim.

I will check out the issue you mentioned. I really like semshi and it's very annoying that I can't use it locally. Hope to get this issue resolved soon.

lkhphuc commented 5 years ago

In particular, it would be interesting to see if you can reproduce the error with the methods I described there (which would also show that the bug can be triggered without Semshi).

@numirias https://github.com/neovim/python-client/issues/341#issuecomment-433717188 I can reproduce the problem over there. But my situation is way worse, once the error pops up, it will pop up again every time I type anything, so basically make it not usable for me, while the error from the error from @balta2ar only show up once at startup.

numirias commented 5 years ago

@balta2ar @lkhphuc Does the error still reproduce with latest Semshi and latest Neovim Python client? ($ pip show neovim should give v0.3.0)

With #26, API calls from threads are now scheduled correctly on the main thread, and I'm hoping that may resolve this issue as well.

balta2ar commented 5 years ago

Hm, I haven't seen this error in a while on neither of my two machines, even before the mentioned pull request. I'll update python-neovim and I'll keep an eye on it.

lkhphuc commented 5 years ago

Thank, I updated everything and can now use Semshi again. But once in a while I got a screenful of error messages but I haven't got time to check whether it's about the race conditions or something else.

languitar commented 5 years ago

I am experiencing exactly this issue again right now. Has anything changed that this happens again?

junhocho commented 4 years ago

https://github.com/numirias/semshi/issues/17#issuecomment-444476291 mentioned "Next Nvim release 0.3.2 (+ accompanying pynvim release) will fix this." I tried re-install semshi package but failed. Re-install neovim worked: sudo apt install neovim