Jedi-vim: Vim freezes on first line comment

Created on 25 Feb 2017  Â·  19Comments  Â·  Source: davidhalter/jedi-vim

Issue

Vim freezes when typing a comment on the first line of the file. Here "freezes" means that it becomes impossible to exit insert mode nor can anything be inserted. This only happens when entering a comment on the first line of the edited Python file. This isn't about ctrl-s :)

Steps to reproduce

To perform the tests I created a clean environment as follows:

  1. vagrant init bento/ubuntu-16.04
  2. vagrant up
  3. vagrant ssh
  4. sudo apt install git vim-nox curl
  5. download vim-plug: curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  6. setup vim-plug (.vimrc contents below)
  7. run :PlugInstall in vim to install jedi-vim
  8. quit vim before running the tests

Contents of .vimrc

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

    Plug 'davidhalter/jedi-vim'

    call plug#end()

The following tests were performed and all of them begin by opening the empty test file test.py and entering insert mode:

  1. type "#dead\\" => Vim is frozen and in insert mode, cursor on second line
  2. type "#dead\\" really fast => Vim exits insert mode and is not frozen
  3. type "carl\#david\\" => Vim exits insert mode and is not frozen
  4. type "#\" => Vim exits insert mode and is not frozen
  5. type "#\" => Vim is in insert mode and is frozen
  6. type "#carl\a david\" => Vim is in insert mode and is frozen

Versions

  • jedi-vim: 682f37792d830bb3211df40e049e992db26e4ec0
  • Vim: 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48)
  • Python: 3.5.2
  • Vim-plug: e3252aae2c9fa6d5ab9bbd3dfe149f35573f4773

Output of the "JediDebugInfo" command (in a Python buffer)

Jedi-vim debug information

Using Python version: 3

  • sys.version: 3.5.2 (default, Nov 17 2016, 17:05:23), [GCC 5.4.0 20160609]
  • site module: /usr/lib/python3.5/site.py
    Jedi path: /home/vagrant/.vim/plugged/jedi-vim/jedi/jedi/__init__.py
  • version: 0.10.0
  • sys_path:

    • /home/vagrant/.vim/plugged/jedi-vim

    • /usr/lib/python35.zip

    • /usr/lib/python3.5

    • /usr/lib/python3.5/plat-x86_64-linux-gnu

    • /usr/lib/python3.5/lib-dynload

    • /usr/local/lib/python3.5/dist-packages

    • /usr/lib/python3/dist-packages

    • _vim_path_

      jedi-vim git version: 682f377

      jedi git submodule status: 70200861661a921016563717487c1ced9993acdb jedi (v0.10.0)

Settings
  omnifunc=
  completeopt=menuone,longest,preview
        Last set from ~/.vim/plugged/jedi-vim/plugin/jedi.vim

Output of the "messages" Vim command

No output other than "Messages maintainer: Bram Moolenaar Bram@vim.org".

Output of "scriptnames" Vim command

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/syntax/syntax.vim
  4: /usr/share/vim/vim74/syntax/synload.vim
  5: /usr/share/vim/vim74/syntax/syncolor.vim
  6: /usr/share/vim/vim74/filetype.vim
  7: ~/.vimrc
  8: ~/.vim/autoload/plug.vim
  9: /usr/share/vim/vim74/ftoff.vim
 10: /usr/share/vim/vim74/ftplugin.vim
 11: /usr/share/vim/vim74/indent.vim
 12: ~/.vim/plugged/jedi-vim/plugin/jedi.vim
 13: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
 14: /usr/share/vim/vim74/plugin/gzip.vim
 15: /usr/share/vim/vim74/plugin/logiPat.vim
 16: /usr/share/vim/vim74/plugin/matchparen.vim
 17: /usr/share/vim/vim74/plugin/netrwPlugin.vim
 18: /usr/share/vim/vim74/plugin/rrhelper.vim
 19: /usr/share/vim/vim74/plugin/spellfile.vim
 20: /usr/share/vim/vim74/plugin/tarPlugin.vim
 21: /usr/share/vim/vim74/plugin/tohtml.vim
 22: /usr/share/vim/vim74/plugin/vimballPlugin.vim
 23: /usr/share/vim/vim74/plugin/zipPlugin.vim
 24: ~/.vim/plugged/jedi-vim/autoload/jedi.vim
jedi-issue

Most helpful comment

I'm on it. Didn't really have time/motivation to look at the issues. I have had 10 issues open that I want to quickly look at. I have already fixed 3. I hope to be able to push it this week.

All 19 comments

My VIM freezes after Ctrl+Space after dot. I see 100% load of CPU with process of VIM.

Ubuntu 14.04 i386

@vitaly-zdanevich no abnormal CPU usage seen in this case.

I'm experiencing a similar issue, but only with specific packages like scipy, numpy, matplotlib, etc.
It takes about 10seconds to load.
It does not freeze, however, for math, os, sys, etc.

I'm using neovim 0.1.7, jedi-vim 0.10.0, on a macOS Sierra.
The following is Jedi-vim debug information.

Jedi-vim debug information

Using Python version: 2

  • sys.version: 2.7.13 (default, Dec 18 2016, 07:03:39), [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
  • site module: /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc
    Jedi path: /Users/jaeho/.vim/plugged/jedi-vim/jedi/jedi/__init__.pyc
  • version: 0.10.0
  • sys_path:

    • /Users/jaeho/.vim/plugged/jedi-vim

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old

    • /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload

    • /usr/local/lib/python2.7/site-packages

    • _vim_path_

      jedi-vim git version: 682f377

      jedi git submodule status: 70200861661a921016563717487c1ced9993acdb jedi (v0.10.0)

Settings
g:force_py_version = '2' (default: 'auto')
g:completions_command = '<C-N>' (default: '<C-Space>')

  omnifunc=jedi#completions
        Last set from ~/.vim/plugged/jedi-vim/after/ftplugin/python/jedi.vim
  completeopt=menuone,longest,preview
        Last set from ~/.vim/plugged/jedi-vim/plugin/jedi.vim
I'm experiencing a similar issue, but only with specific packages like scipy, numpy, matplotlib, etc.

@Zeta611 this issue occurs with an empty file. What do you mean by specific packages? When editing empty files within those packages? When having imported modules from those packages? Or are you referring to @vitaly-zdanevich's 100% CPU issue? To me it appears that that has nothing to do with this issue and it might be warranted to create another one because this one has ostensibly nothing to do with autocompletion.

Confirmed in Vim, but not Neovim.

It is triggered caused by g:jedi#show_call_signatures (both 1 and 2, using 0 does not trigger it).

set nocompatible

let script_dir = fnamemodify(expand('<sfile>'), ':h')
let &runtimepath .= ','.script_dir.','.script_dir.'/after'

let g:jedi#auto_vim_configuration = 1
" let g:jedi#show_call_signatures=1

syntax on
filetype plugin indent on

TEST CASE:

1. echo -n '#dead' > t-dead.py
2. vim -u minimal.vimrc '+norm $' '+startinsert' t-dead.py
3. Press `Esc`, then `A`.

(It also happens in Neovim, but call signatures are a bit buggy there))

git-bisected to https://github.com/davidhalter/jedi/commit/8f4b86289249bc6b10ec8982d73777ebc1b169fb in Jedi.

It seems like there is an endless loop via get_script().call_signatures() used by jedi-vim.

/cc @davidhalter

I cannot reproduce it with Jedi directly though

% python -c "print(__import__('jedi').Script('#dead', 1, 5, '/home/user/.dotfiles/vim/plugged/jedi-vim/t-dead.py', 'utf-8').call_signatures())"
[]

It needs to be called twice:

% python -c "print(__import__('jedi').Script('#dead', 1, 5, '…/vim/plugged/jedi-vim/t-dead.py', 'utf-8').call_signatures()); print(__import__('jedi').Script('#dead', 1, 5, '…/vim/plugged/jedi-vim/t-dead.py', 'utf-8').call_signatures());"
[]
^CTraceback (most recent call last):
  File "…/vim/plugged/jedi-vim/jedi/jedi/cache.py", line 87, in wrapper
    return dct[key]
KeyError: ((), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/tree.py", line 311, in get_start_pos_of_prefix
    return self.get_previous_leaf().end_pos
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/tree.py", line 256, in get_previous_leaf
    raise IndexError('Cannot access the previous element of the first one.')
IndexError: Cannot access the previous element of the first one.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "…/vim/plugged/jedi-vim/jedi/jedi/api/__init__.py", line 300, in call_signatures
    helpers.get_call_signature_details(self._get_module_node(), self._pos)
  File "…/vim/plugged/jedi-vim/jedi/jedi/cache.py", line 89, in wrapper
    result = method(self, *args, **kwargs)
  File "…/vim/plugged/jedi-vim/jedi/jedi/api/__init__.py", line 137, in _get_module_node
    parser = FastParser(self._grammar, self._source, self.path)
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/diff.py", line 33, in __call__
    parser.module = parser._parsed = d.update(new_lines)
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/diff.py", line 178, in update
    self._parse(until_line=j2)
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/diff.py", line 292, in _parse
    nodes[0].get_start_pos_of_prefix()[0],
  File "…/vim/plugged/jedi-vim/jedi/jedi/parser/tree.py", line 313, in get_start_pos_of_prefix
    return self.line - self.prefix.count('\n'), 0  # It's the first leaf.
KeyboardInterrupt

@blueyed that was fast. Very nice.

Thanks a lot for debugging @blueyed !

@denarced No, I'm not experiencing CPU 100% issue.
What I meant by "specific packages":
When I edit a file and import a module from a package using from a import b, e.g. from matplotlib import pyplot, (neo)vim freezes for about ten seconds when I type space after matplotlib.
It also freezes when I type .(dot) after matplotlib.
However, the lag takes only about .5 seconds or so for packages like sys, os, math, etc.

Happens here also --- hard freeze after entering the "#" comment after the she-bang line.
Fortunately you can write the fist two lines with any other editor and then go using jedi... ;-)

@Rmano I noticed the issue with shebang. I have since added it with echo :)

lol. The work arounds :-D

@davidhalter
We should have a bugfix release with a fix for this severe issue, and possibly others.
I could try preparing something by cherry-picking, but maybe you want to do it instead?

I'm on it. Didn't really have time/motivation to look at the issues. I have had 10 issues open that I want to quickly look at. I have already fixed 3. I hope to be able to push it this week.

Should be fixed by now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hungrybirder picture hungrybirder  Â·  11Comments

ayeganovgb picture ayeganovgb  Â·  11Comments

soulcmdc-zz picture soulcmdc-zz  Â·  3Comments

optix2000 picture optix2000  Â·  6Comments

yevhen-m picture yevhen-m  Â·  8Comments