fgrsnau / ncm2-otherbuf

ncm2 plugin for completing words in other buffers
18 stars 3 forks source link

Errors #4

Closed bbtdev closed 5 years ago

bbtdev commented 5 years ago

Hey first all thank you for doing this, I needed this completion back in my life.

Sadly I am encountering some issues. This is in my messages and the completion source does not work.

[ncm2_otherbuf@yarp]   File "/home/bogdan/.local/lib/python3.6/site-packages/pynvim/api/common.py", line 51, in request                                                                                                      
[ncm2_otherbuf@yarp]     return self._session.request(name, self, *args, **kwargs)                                                                                                                                           
[ncm2_otherbuf@yarp]   File "/home/bogdan/.local/lib/python3.6/site-packages/pynvim/api/nvim.py", line 182, in request                                                                                                       
[ncm2_otherbuf@yarp]     res = self._session.request(name, *args, **kwargs)                                                                                                                                                  
[ncm2_otherbuf@yarp]   File "/home/bogdan/.local/lib/python3.6/site-packages/pynvim/msgpack_rpc/session.py", line 102, in request                                                                                            
[ncm2_otherbuf@yarp]     raise self.error_wrapper(err)                                                                                                                                                                       
[ncm2_otherbuf@yarp] pynvim.api.nvim.NvimError: b'Invalid buffer id'                                                                                                                                                         
[ncm2_otherbuf@yarp] error caught in notification handler 'on_warmup [{'filepath': '', 'source': {'subscope_enable': 0, 'early_cache': 0, 'name': 'otherbuf', 'priority': 4, 'mark': 'o', 'on_warmup': 'ncm2_otherbuf#on_warm
up', 'ready': 1, 'enable': 1, 'auto_popup': 1, 'on_complete': 'ncm2_otherbuf#on_complete'}, 'scope_match': '', 'scope_level': 1, 'lnum': 1, 'bufnr': 5, 'changedtick': 2, 'typed': '', 'ccol': 1, 'filetype': '', 'curpos': [
0, 1, 1, 0, 1], 'tick': [[0, 1, 1], 0], 'early_cache': False, 'context_id': 25, 'scope': '', 'bcol': 1}]'                                                                                                                    
[ncm2_otherbuf@yarp] Traceback (most recent call last):                                                                                                                                                                      
[ncm2_otherbuf@yarp]   File "/home/bogdan/.local/share/nvim/plugged/nvim-yarp/pythonx/yarp.py", line 30, in on_notification                                                                                                  
[ncm2_otherbuf@yarp]     getattr(module_obj, method)(*args)                                                                                                                                                                  
[ncm2_otherbuf@yarp]   File "/home/bogdan/.local/share/nvim/plugged/ncm2-otherbuf/pythonx/ncm2_otherbuf.py", line 82, in on_warmup                                                                                           
[ncm2_otherbuf@yarp]     self.buffers[self.active_bufnr].changed = True                                                                                                                                                      
[ncm2_otherbuf@yarp] KeyError: 4   
fgrsnau commented 5 years ago

Hm. This just happens for some buffers it seems.

I can trigger this reliably by issuing :help $SOMETHING. It seems that the on_warmup method is called while another invocation of on_warmup is only half-way through.

This is bad, as the current code is not reentrant-safe. Locking is impossible as this would create a deadlocking in pynvim's msgpack-code.

The following workaround works for me:

diff --git a/pythonx/ncm2_otherbuf.py b/pythonx/ncm2_otherbuf.py
index dc1ad66..2b78e4b 100644
--- a/pythonx/ncm2_otherbuf.py
+++ b/pythonx/ncm2_otherbuf.py
@@ -80,9 +81,9 @@ class Source(Ncm2Source):

         if self.active_bufnr is not None:
             self.buffers[self.active_bufnr].changed = True
-        self.active_bufnr = bufnr

         self.update()
+        self.active_bufnr = bufnr

 source = Source(vim)

I would love to fully understand what's going on and how other nvim plugins handle such cases.

fgrsnau commented 5 years ago

@bbtdev Can you check that my change really fixes your issue?

bbtdev commented 5 years ago

@fgrsnau today there was a lot of bug fixing and trial and error, I didn't write so much code, so I did not noticed. You will get an update for me tomorrow or in a 2 days, when I am back to coding (proper testing for this plugin). Is this okay?

bbtdev commented 5 years ago

@fgrsnau I had an error today, when I opened with FZF the :History buffer. I can't reproduce atm, but I work with Fzf a lot, so I will keep you posted.