ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.45k stars 2.8k forks source link

Error when opening a file via Startify #2680

Closed klaxalk closed 7 years ago

klaxalk commented 7 years ago

Issue Prelude

Issue Details

Hello, since the commit 8c6efb42148e2e84f33b3510e6d0539dcf11b6a1 on July 4th, YCM outputs following error when openning a file (e.g. ~/.bashrc) using Startify homescreen history (or bookmarks) (https://github.com/mhinz/vim-startify):

Error detected while processing function <SNR>26_OnFileTypeSet[10]..<SNR>26_OnFileReadyToParse:
line    9:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/autoload/../python/ycm/youcompleteme.py", line 378, in OnFileReadyToParse
    self._current_buffer.SendParseRequest( extra_data )
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/autoload/../python/ycm/buffer.py", line 56, in SendParseRequest
    self._parse_tick = self._ChangedTick()
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/autoload/../python/ycm/buffer.py", line 97, in _ChangedTick
    return vimsupport.GetBufferChangedTick( self.number )
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/autoload/../python/ycm/vimsupport.py", line 155, in GetBufferChangedTick
    return GetIntValue( 'getbufvar({0}, "changedtick")'.format( bufnr ) )
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/autoload/../python/ycm/vimsupport.py", line 618, in GetIntValue
    return int( vim.eval( variable ) )
  File "/home/klaxalk/git/linux-setup/appconfig/vim/dotvim/plugged/youcompleteme/third_party/ycmd/third_party/python-future/src/future/types/newint.py", line 76, in __new__
    return super(newint, cls).__new__(cls, val)
ValueError: invalid literal for long() with base 10: ''

Include steps to reproduce here

Vim 8.0.0628 compiled from sources (commit f085f4266e07b36279c56d43fd0d73ed080046ae) as

./configure --with-features=huge \
      --enable-multibyte \
      --enable-rubyinterp=yes \
      --enable-pythoninterp=yes \
      --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
      --enable-perlinterp=yes \
      --enable-luainterp=yes \
      --enable-gui=gtk2 --enable-cscope --prefix=/usr
cd src
make
cd ../
make VIMRUNTIMEDIR=/usr/share/vim/vim80
sudo make install

Minimal .vimrc (using vim-plug) to reproduce the error:

set nocompatible
call plug#begin("~/.vim/plugged")

Plug 'mhinz/vim-startify', { 'commit': '53c53b24440d14d7886484ad662549fc78550c40' }
Plug 'valloric/youcompleteme', { 'commit': '8c6efb42148e2e84f33b3510e6d0539dcf11b6a1' }

call plug#end()

YCM is installed as

./install.py --all

Diagnostic data

Output of vim --version

https://gist.github.com/klaxalk/1c3ca79d5cb14095689529655ff1b20b

Output of YcmDebugInfo

Printing YouCompleteMe debug information... -- Client logfile: /tmp/ycm_KHGxcf.log -- Server Python interpreter: /usr/bin/python -- Server Python version: 2.7.12 -- Server has Clang support compiled in: True -- Clang version: clang version 4.0.0 (tags/RELEASE_400/final) -- Extra configuration file found and loaded -- Extra configuration path: /home/klaxalk/.ycm_extra_conf.py -- Server running at: http://127.0.0.1:38676 -- Server process ID: 17068 -- Server logfiles: -- /tmp/ycmd_38676_stdout_HyZHGf.log -- /tmp/ycmd_38676_stderr_MuZoUn.log

Contents of YCM, ycmd and completion engine logfiles

ycmd_stdout log serving on http://127.0.0.1:38676

ycmd_stderr log https://gist.github.com/klaxalk/b4e6740c6154a4d792f2c473dd90d913

OS version, distribution, etc.

Ubuntu 16.04 64bit

micbou commented 7 years ago

Thanks for the report. This is related to the issue found by @davits in PR https://github.com/Valloric/YouCompleteMe/pull/2677:

Found and fixed bug when YouCompleteMe._current_buffer were not updating correctly/in time. It was happening because FileType event in Vim comes before BufEnter, and reparse from BufEnter is blocked by s:VisitedBufferRequiresReparse(). So it will end up sending file parse event for the previous buffer from FileType and updating current buffer to current one on BufVisit, but not sending parse event for it.

In that particular case, YCM calls getbufvar on a deleted buffer (the one created by Startify). When the buffer doesn't exist, this function returns an empty string that YCM tries to convert to an integer and the error ensues. This should be fixed by PR #2677 but I think we also need to remove deleted buffers from YCM own buffers list on the BufferUnload event or this list will grow indefinitely. I don't know if Vim reuse buffer numbers from deleted buffers but this could be an issue too.

micbou commented 7 years ago

Fixed by PR #2677.