Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function signature explodes screen on some functions #418

Closed
hath995 opened this issue May 13, 2015 · 20 comments
Closed

Function signature explodes screen on some functions #418

hath995 opened this issue May 13, 2015 · 20 comments

Comments

@hath995
Copy link

hath995 commented May 13, 2015

When editing parameters of django.shortcuts render (django 1.8) the function signature helper throws an errror and renders the screen un readable. A :redraw! is required to clear the screen of the error message. This is the part of the error message I can access. Edit: It seems the decorator I'm trying to apply it the issue not the django function. Removing the decorator on the view prevents the error from happening.

le()
~ File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/user_context.py", line 332, in module
~ return self._parser().module
~ File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/cache.py", line 143, in wrapper
~ result = func(self)
~ File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/user_context.py", line 277, in _parser
~ parser = FastParser(self._grammar, self._source, self._path)
~ File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 109, in call
~ p.update(source)
~ File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 257, in update
-- INSERT -- self._parse(source) 8,53 All
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 383, in _parse
line_offset, nodes)
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 435, in _get_node
p = Parser(self._grammar, parser_code, self.module_path, tokenizer=tokenizer)
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/init.py", line 155, in init
self.module = p.parse(self._tokenize(tokenizer))
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/pgen2/parse.py", line 106, in parse
if self.addtoken(type, value, prefix, start_pos):
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/pgen2/parse.py", line 170, in addtoken
value, start_pos, prefix, self.addtoken)
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/init.py", line 269, in error_recovery
self._stack_removal(grammar, stack, index + 1, value, start_pos)
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/init.py", line 304, in _stack_removal
clear_names(children=node[1])
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/init.py", line 294, in clear_names
clear_names(c.children)
File "/home/vagrant/.vim/bundle/jedi-vim/jedi/jedi/parser/init.py", line 298, in clear_names
self._scope_names_stack[-1][c.value].remove(c)
KeyError: u'staff_user_required'

:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
Included patches: 1-52
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+acl             -clientserver    +cscope          +emacs_tags      +folding         +keymap          +menu            +mouse_netterm   +netbeans_intg   -python3         -sniff           -tcl             +virtualedit     +writebackup
+arabic          -clipboard       +cursorbind      +eval            -footer          +langmap         +mksession       +mouse_sgr       +path_extra      +quickfix        +startuptime     +terminfo        +visual          -X11
+autocmd         +cmdline_compl   +cursorshape     +ex_extra        +fork()          +libcall         +modify_fname    -mouse_sysmouse  -perl            +reltime         +statusline      +termresponse    +visualextra     -xfontset
-balloon_eval    +cmdline_hist    +dialog_con      +extra_search    +gettext         +linebreak       +mouse           +mouse_urxvt     +persistent_undo +rightleft       -sun_workshop    +textobjects     +viminfo         -xim
-browse          +cmdline_info    +diff            +farsi           -hangul_input    +lispindent      -mouseshape      +mouse_xterm     +postscript      -ruby            +syntax          +title           +vreplace        -xsmp
++builtin_terms  +comments        +digraphs        +file_in_path    +iconv           +listcmds        +mouse_dec       +multi_byte      +printer         +scrollbind      +tag_binary      -toolbar         +wildignore      -xterm_clipboard
+byte_offset     +conceal         -dnd             +find_in_path    +insert_expand   +localmap        +mouse_gpm       +multi_lang      +profile         +signs           +tag_old_static  +user_commands   +wildmenu        -xterm_save
+cindent         +cryptv          -ebcdic          +float           +jumplist        -lua             -mouse_jsbterm   -mzscheme        +python          +smartindent     -tag_any_white   +vertsplit       +windows         -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -W
l,-O1 -Wl,-Bsymbolic-functions

These are the plugins I'm trying to use.
argtextobj.vim CamelCaseMotion emmet-vim flake8-vim jedi-vim nerdtree tern_for_vim vim-airline vim-over vim-surround

the decorator

from django.contrib.auth.decorators import user_passes_test, login_required

def staff_user_required(f):
    superuser_check = user_passes_test(lambda user: user.is_staff)(f)

    return login_required(superuser_check)
@davidhalter
Copy link
Owner

It's a jedi issue, so your plugins don't really matter.

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

the function signature helper throws an errror and renders the screen unreadable

That should not happen in jedi-vim - errors should show up in :mess only.

@hath995
How do you trigger this exactly?
I've tried your code snippet from above, but could not trigger it from there.
Is the snippet enough for you? Where do you edit it?

@blueyed blueyed added the bug label May 13, 2015
@hath995
Copy link
Author

hath995 commented May 13, 2015

My environment is an ubuntu vagrant, running vim in screen. uname -a
3.13.0-49-generic #83-Ubuntu SMP Fri Apr 10 20:11:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
I just tried triggering it outside of screen and it reproduces. This is the whole file at this point.

from privatelibs import staff_user_required
from django.shortcuts import render

@staff_user_required
def fancyview(request):
    return render(request, 'fancyview.html', {})

I move my cursor into 'fancyview.html' type 2 characters and the error appears.

@hath995
Copy link
Author

hath995 commented May 13, 2015

Actually type two characters into any of the parameters of render causes the error.

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

Does it happen with the following then for you, too?
When typing anything after render( at the end?

It does not happen for me, but I get no signatures - although jedi-vim is able to resolve/goto the render method correctly.

I am using Django 1.8.

from django.contrib.auth.decorators import user_passes_test, login_required

def staff_user_required(f):
    superuser_check = user_passes_test(lambda user: user.is_staff)(f)

    return login_required(superuser_check)

from django.shortcuts import render

@staff_user_required
def fancyview(request):
    return render(

@hath995
Copy link
Author

hath995 commented May 13, 2015

yes, it does.

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

Weird.

I've tried it with g:jedi#show_call_signatures=1 now (I am using 2 currently by default), and it works - the signatures show up.

So there's some other issue with g:jedi#show_call_signatures=2 not showing anything for me.

Can you test it with g:jedi#show_call_signatures=2, please?
What are your other jedi-vim settings?

Do you see anything in :mess, e.g. the uncorrupted traceback?

Are you using latest jedi-vim and jedi?

@hath995
Copy link
Author

hath995 commented May 13, 2015

It happens when show_call_signatures=1 but not when =2. I don't see the signature at all when =2.
:mess
E325: ATTENTION
"persistence/views.py" 7L, 259C
Scanning tags.
"persistence/views.py" 7L, 279C written
"persistence/views.py" 7L, 279C written

@hath995
Copy link
Author

hath995 commented May 13, 2015

jedibug

@hath995
Copy link
Author

hath995 commented May 13, 2015

Yes, I pulled from jedi-vim master this week.

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

I could reproduce it now, but it shows up in :mess for me only.

It's really a jedi issue, but it's odd that it messes up your buffer through jedi-vim.

The code to handle the exception in jedi-vim is:

def catch_and_print_exceptions(func):
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except (Exception, vim.error):
            print(traceback.format_exc())
            return None
    return wrapper

So it uses just print.

What Vim version are you using?
Does the following command also mess with your buffer?

:py for i in range(1, 15): print(i)

For reference, here's the full traceback:

Traceback (most recent call last):
  File "…/vim/neobundles/jedi/jedi/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '_user_stmt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/vim/neobundles/jedi/jedi/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '__parser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 294, in clear_names
    clear_names(c.children)
AttributeError: 'Name' object has no attribute 'children'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/vim/neobundles/jedi/jedi_vim.py", line 110, in wrapper
    return func(*args, **kwargs)
  File "…/vim/neobundles/jedi/jedi_vim.py", line 321, in show_call_signatures
    signatures = get_script().call_signatures()
  File "…/vim/neobundles/jedi/jedi/jedi/api/__init__.py", line 515, in call_signatures
    stmt = self._get_under_cursor_stmt(call_txt, start_pos)
  File "…/vim/neobundles/jedi/jedi/jedi/evaluate/cache.py", line 41, in wrapper
    rv = function(obj, *args, **kwargs)
  File "…/vim/neobundles/jedi/jedi/jedi/api/__init__.py", line 309, in _get_under_cursor_stmt
    user_stmt = self._parser.user_stmt()
  File "…/vim/neobundles/jedi/jedi/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/user_context.py", line 293, in user_stmt
    module = self.module()
  File "…/vim/neobundles/jedi/jedi/jedi/parser/user_context.py", line 339, in module
    return self._parser().module
  File "…/vim/neobundles/jedi/jedi/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/user_context.py", line 283, in _parser
    parser = FastParser(self._grammar, self._source, self._path)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/fast.py", line 109, in __call__
    p.update(source)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/fast.py", line 257, in update
    self._parse(source)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/fast.py", line 383, in _parse
    line_offset, nodes)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/fast.py", line 435, in _get_node
    p = Parser(self._grammar, parser_code, self.module_path, tokenizer=tokenizer)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 155, in __init__
    self.module = p.parse(self._tokenize(tokenizer))
  File "…/vim/neobundles/jedi/jedi/jedi/parser/pgen2/parse.py", line 106, in parse
    if self.addtoken(type, value, prefix, start_pos):
  File "…/vim/neobundles/jedi/jedi/jedi/parser/pgen2/parse.py", line 170, in addtoken
    value, start_pos, prefix, self.addtoken)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 269, in error_recovery
    self._stack_removal(grammar, stack, index + 1, value, start_pos)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 304, in _stack_removal
    clear_names(children=node[1])
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 294, in clear_names
    clear_names(c.children)
  File "…/vim/neobundles/jedi/jedi/jedi/parser/__init__.py", line 298, in clear_names
    self._scope_names_stack[-1][c.value].remove(c)
KeyError: 'staff_user_required'

@davidhalter
Should we create a issue for this in jedi-vim to track it there?

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

It happens when show_call_signatures=1 but not when =2. I don't see the signature at all when =2.

You probably have to restart Vim, or reload the buffer (:e) before that works - because it needs some setup.

It seems like the command line signatures only show up with Django 1.7.x.. (for this example)!

@hath995
Copy link
Author

hath995 commented May 13, 2015

See the op for my vim version. I ran the command and it does indeed mess with my buffer. A redraw! is required to clear it.
screen shot 2015-05-13 at 2 47 49 pm

@blueyed
Copy link
Collaborator

blueyed commented May 13, 2015

Oh, yeah.
So your Vim is apparently broken in this regard - and rather old (7.4.52). Ubuntu Trusty?

You might try a newer version (to fix the jedi-vim side of this issue).
It might be a good opportunity to give Neovim a shot also.. :)

@davidhalter
Copy link
Owner

BTW I'm still using VIM 7.3 :)

@davehalter: should we create a issue for this in jedi-vim to track it there?

I don't care. For me personally, linking to Jedi (by using the jedi-issue label) is good enough.

@hath995
Copy link
Author

hath995 commented May 13, 2015

Switching to neovim was mostly painless. It does "fix" the error, though I'm still curious why adding a decorator to the function would cause that error on an unrelated function inside.

@davidhalter
Copy link
Owner

Strange, especially since the error happens somewhere deep within Jedi.

@blueyed blueyed removed the bug label May 13, 2015
@jamesfe
Copy link

jamesfe commented Dec 11, 2015

When I define a @staticmethod on a class, as soon as I type 'def xyz(' at the opening parenthesis, my screen scrambles. Here is the traceback - I am posting here because it is so similar to the other tracebacks and the symptoms are similar. Let me know if there is any way I can help.

Generally I fix this by disabling jedi vim if I find myself doing a task that involves many decorators.

File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/user_context.py", line 293, in user_stmt
 module = self.module()
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/user_context.py", line 339, in module
 return self._parser().module
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/cache.py", line 143, in wrapper
 result = func(self)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/user_context.py", line 283, in _parser
 parser = FastParser(self._grammar, self._source, self._path)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 106, in __call__
 p = super(CachedFastParser, self).__call__(grammar, source, module_path)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 243, in __init__
 self.update(source)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 257, in update
 self._parse(source)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 383, in _parse
 line_offset, nodes)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/fast.py", line 435, in _get_node
 p = Parser(self._grammar, parser_code, self.module_path, tokenizer=tokenizer)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/__init__.py", line 155, in __init__
 self.module = p.parse(self._tokenize(tokenizer))
File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/pgen2/parse.py", line 106, in parse
 if self.addtoken(type, value, prefix, start_pos):
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/pgen2/parse.py", line 170, in addtoken
 value, start_pos, prefix, self.addtoken)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/__init__.py", line 269, in error_recovery
 self._stack_removal(grammar, stack, index + 1, value, start_pos)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/__init__.py", line 304, in _stack_removal
 clear_names(children=node[1])
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/__init__.py", line 294, in clear_names
 clear_names(c.children)
 File "/Users/jamesfe/.vim/bundle/jedi-vim/jedi/jedi/parser/__init__.py", line 298, in clear_names
 self._scope_names_stack[-1][c.value].remove(c)
 KeyError: u'staticmethod'

@davidhalter
Copy link
Owner

This issue has been fixed in Jedi's dev branch. It has been reported to Jedi a number of times.

@hath995
Copy link
Author

hath995 commented Jul 21, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants