ncm2 / ncm2-pyclang

Cached, fast C/C++ completion for ncm2
MIT License
45 stars 1 forks source link

pop up error when I write func parameter #14

Closed fcying closed 6 years ago

fcying commented 6 years ago

when I write a struct var in func parameter, pop up error. write same word in new line work fine.

reproduce way:

vim src/a.c
3G
o
test_func(te
[ncm2_pyclang_proc@yarp] error caught while executing async callback:
[ncm2_pyclang_proc@yarp] TypeError('exceptions must derive from BaseException',)
[ncm2_pyclang_proc@yarp] Traceback (most recent call last):
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 73, in raise_ex
[ncm2_pyclang_proc@yarp]     raise ex
[ncm2_pyclang_proc@yarp] TypeError: exceptions must derive from BaseException
[ncm2_pyclang_proc@yarp]  
[ncm2_pyclang_proc@yarp] the call was requested at
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 884, in _bootstrap
[ncm2_pyclang_proc@yarp]     self._bootstrap_inner()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 916, in _bootstrap_inner
[ncm2_pyclang_proc@yarp]     self.run()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 864, in run
[ncm2_pyclang_proc@yarp]     self._target(*self._args, **self._kwargs)
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 74, in worker_loop
[ncm2_pyclang_proc@yarp]     nvim.async_call(raise_ex)

image

image

clang_test.zip

fcying commented 6 years ago

after modify def raise_ex() to class raise_ex(), it can raise the right log, it's abnormal by use let g:ncm2#matcher = 'substrfuzzy', if I use default matcher, it work fine.

diff --git a/pythonx/ncm2_pyclang_proc.py b/pythonx/ncm2_pyclang_proc.py
index d25eaee..fce4ad6 100644
--- a/pythonx/ncm2_pyclang_proc.py
+++ b/pythonx/ncm2_pyclang_proc.py
@@ -69,7 +69,7 @@ class Source(Ncm2Source):
             except Exception as ex:
                 from neovim import Nvim
                 nvim = self.nvim  # type: Nvim
-                def raise_ex():
+                class raise_ex():
                     raise ex
                 nvim.async_call(raise_ex)
             finally:
[ncm2_pyclang_proc@yarp] Exception in thread Thread-1:
[ncm2_pyclang_proc@yarp] Traceback (most recent call last):
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 916, in _bootstrap_inner
[ncm2_pyclang_proc@yarp]     self.run()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.pyenv/versions/3.6-dev/lib/python3.6/threading.py", line 864, in run
[ncm2_pyclang_proc@yarp]     self._target(*self._args, **self._kwargs)
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 72, in worker_loop
[ncm2_pyclang_proc@yarp]     class raise_ex():
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 73, in raise_ex
[ncm2_pyclang_proc@yarp]     raise ex
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 65, in worker_loop
[ncm2_pyclang_proc@yarp]     task()
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 333, in <lambda>
[ncm2_pyclang_proc@yarp]     lambda: self.on_complete_task(context, data, lines)])
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 395, in on_complete_task
[ncm2_pyclang_proc@yarp]     if not matcher(base, item):
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2/pythonx/ncm2_matcher/substrfuzzy.py", line 100, in match
[ncm2_pyclang_proc@yarp]     hl = fuzzy_match(b, m[key], chcmp)
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2/pythonx/ncm2_matcher/substrfuzzy.py", line 18, in fuzzy_match
[ncm2_pyclang_proc@yarp]     return substr_fuzzy_match(b, s, abbrs, chcmp)
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2/pythonx/ncm2_matcher/substrfuzzy.py", line 54, in substr_fuzzy_match
[ncm2_pyclang_proc@yarp]     start = abbrs[0]
[ncm2_pyclang_proc@yarp] IndexError: list index out of range
roxma commented 6 years ago
[ncm2_pyclang_proc@yarp] Traceback (most recent call last):
[ncm2_pyclang_proc@yarp]   File "/home/fcying/.vim/plugged/ncm2-pyclang/pythonx/ncm2_pyclang_proc.py", line 73, in raise_ex
[ncm2_pyclang_proc@yarp]     raise ex
[ncm2_pyclang_proc@yarp] TypeError: exceptions must derive from BaseException

after modify def raise_ex() to class raise_ex(), it can raise the right log

Why ?

fcying commented 6 years ago

https://www.cnblogs.com/bidepanpan/p/7115153.html

TypeError: exceptions must derive from BaseException

异常必须从基础异常类中派生。然后看了下自己的第一行。用的是def,这是创建了一个方法。。而不是一个类,简单的语法错误。只要将第一行的def改成class