ycm-core / YouCompleteMe

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

Exception using ctrlp.vim when Java Language Server is initialized #3150

Closed dwoznicki closed 5 years ago

dwoznicki commented 6 years ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

A quick overview: This issue refers to ctrlp.vim (https://github.com/ctrlpvim/ctrlp.vim) and a possible conflict while using the java completer for YouCompleteMe. I can reproduce the issue without any configuration for YouCompleteMe or ctrlp.vim.

  1. mkdir -p /tmp/hello/.git (ctrlp.vim uses the .git dir to find the project root by default)
  2. Add file /tmp/hello/Hello.java
    public class Hello {                                                             
    public static void main(String[] arv) throws Exception {                     
        System.out.println("Hello.");                                            
    }                                                                            
    }
  3. vim /tmp/hello/Hello.java, quickly press <CTRL> + p to open ctrlp.vim window and type a random character. a. This must be done before the Java Language Server finishes loading b. The ctrlp.vim window with the typed character must still be open when the Java Language Server finishes loading
  4. Error occurs once the Java Language Server finishes loading

Probably YCM to initialize the Java Language Server without affecting the ctrlp.vim I have open.

I get an exception stack trace in my vim window with Press ENTER or type command to continue between each item in the stack. I removed the Press ENTER or type command to continue logs from the trace below. This error does not appear to be logged in any :YcmToggleLogs files.

Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
Traceback (most recent call last):
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "<string>", line 1, in <module>
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/youcompleteme.py", line 427, in OnPeriodicTick
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    if not self._message_poll_request.Poll( self ):
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/client/messages_request.py", line 72, in Poll
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    poll_again = _HandlePollResponse( response, diagnostics_handler )
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/client/messages_request.py", line 90, in _Handle
PollResponse
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    notification[ 'diagnostics' ] )
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/youcompleteme.py", line 391, in UpdateWithNewDia
gnosticsForFile
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    self._buffers[ bufnr ].UpdateWithNewDiagnostics( diagnostics )
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/buffer.py", line 84, in UpdateWithNewDiagnostics

Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    self._diag_interface.UpdateWithNewDiagnostics( diagnostics )
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/diagnostic_interface.py", line 77, in UpdateWith
NewDiagnostics
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    self.UpdateMatches()
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/diagnostic_interface.py", line 153, in UpdateMat
ches
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    vimsupport.RemoveDiagnosticMatch( match )
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    next(self.gen)
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
  File "/home/danwoz/.vim/bundle/YouCompleteMe/autoload/../python/ycm/vimsupport.py", line 1243, in CurrentWindow
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
    vim.current.window = current_window
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
vim.error: attempt to refer to deleted window
Error detected while processing function <SNR>53_ReceiveMessages[1]..<SNR>53_Pyeval:
E858: Eval did not return a valid python object

Diagnostic data

Output of vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 12 2018 15:05:53)
Included patches: 1-369
Modified by jonathonf.fernyhough@york.ac.uk
Compiled by jonathonf.fernyhough@york.ac.uk
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    +tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               +perl              +vartabs
+clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           -python            +viminfo
+conceal           +linebreak         +python3           +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       +lua               +ruby              +writebackup
+dialog_con_gui    +menu              +scrollbind        +X11
+diff              +mksession         +signs             -xfontset
+digraphs          +modify_fname      +smartindent       +xim
+dnd               +mouse             +startuptime       +xpm
-ebcdic            +mouseshape        +statusline        +xsmp_interact
+emacs_tags        +mouse_dec         -sun_workshop      +xterm_clipboard
+eval              +mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary        
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.22/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -lpython3.5m -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-2.3 -lpthread -lgmp -ldl -lcrypt -lm     

Output of YcmDebugInfo

Printing YouCompleteMe debug information...
-- Client logfile: /tmp/ycm_x2nwqud2.log
-- Server Python interpreter: /usr/bin/python
-- Server Python version: 2.7.12
-- Server has Clang support compiled in: True
-- Clang version: clang version 6.0.0 (tags/RELEASE_600/final)
-- No extra configuration file found
-- Java completer debug information:
--   jdt.ls Java Language Server running
--   jdt.ls Java Language Server process ID: 22919
--   jdt.ls Java Language Server executable: /home/danwoz/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/eclip
se.jdt.ls/target/repository/plugins/org.eclipse.equinox.launcher_1.5.0.v20180207-1446.jar
--   jdt.ls Java Language Server logfiles:
--     /tmp/jdt.ls_stderr_MtAtmu.log
--     /home/danwoz/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/eclipse.jdt.ls/workspace/temp/tmpniYwor/.me
tadata/.log
--   jdt.ls Java Language Server Startup Status: 100% Starting Java Language Server
--   jdt.ls Java Language Server Java Path: /usr/bin/java
--   jdt.ls Java Language Server Launcher Config.: /home/danwoz/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party
/eclipse.jdt.ls/target/repository/config_linux
--   jdt.ls Java Language Server Project Directory: /tmp/hello
--   jdt.ls Java Language Server Workspace Path: /home/danwoz/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/e
clipse.jdt.ls/workspace/temp/tmpniYwor
-- Server running at: http://127.0.0.1:43189
-- Server process ID: 22872
-- Server logfiles:
--   /tmp/ycmd_43189_stdout_fodj7y_d.log
--   /tmp/ycmd_43189_stderr_v72ugy9s.log

Contents of YCM, ycmd and completion engine logfiles

:YcmToggleLogs output:

Which logfile do you wish to open (or close if already open)?
1: .log
2: jdt.ls_stderr_MtAtmu.log
3: ycm_x2nwqud2.log
4: ycmd_43189_stderr_v72ugy9s.log
5: ycmd_43189_stdout_fodj7y_d.log

.log output:

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-09-20 10:55:14.091                       
!MESSAGE >> document/didClose                                                    

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-09-20 10:55:14.097                       
!MESSAGE Clearing problems for /Hello.java

jdt.ls_stderr_MtAtmu.log output:

ycm_x2nwqud2.log output:

ycmd_43189_stderr_v72ugy9s.log output: https://gist.github.com/dwoznicki/0dbcd691021e2c49143c9952d58db75f

ycmd_43189_stdout_fodj7y_d.log output:

serving on http://localhost:43189

OS version, distribution, etc.

Ubuntu 16.04.1 LTS (GNU/Linux 4.12.0-041200rc1-generic x86_64)

Output of build/install commands

Include link to a gist containing the invocation and entire output of install.py if reporting an installation issue.

bstaletic commented 6 years ago

I can't say that I understand how is this happening, but that backtrace shows that current_window in vim.current.window = current_window (vimsupport.py, CurrentWindow()) refers to a deleted window.

micbou commented 6 years ago

Thanks for the report. This happens because YCM go through all the windows to update the diagnostics once the Java server is initialized. During this operation, the WinEnter and WinLeave events are ignored but not the BufEnter and BufLeave ones which are also triggered when moving to a different window. The issue is that ctrlp.vim delete its buffer on the BufLeave event. When YCM tries to go back to the initial window (the ctrlp.vim one), it fails because the window doesn't exist anymore. The BufEnter and BufLeave events should be ignored as well. See PR https://github.com/Valloric/YouCompleteMe/pull/3152.

bstaletic commented 5 years ago

Since #3247 is merged and reverted #3024, this bug is no longer valid.