AndrewRadev / vimrunner

Control a vim instance through ruby code
MIT License
238 stars 13 forks source link

Vimrunner::TimeoutError: Is x11 server running? #11

Closed emilford closed 11 years ago

emilford commented 11 years ago

Hi,

I am trying to write my first specs using vimrunner for a new vim plugin I am working on. I keep getting the following error after having installed XQuartz and MacVim:

Failure/Error: vim = Vimrunner.start Vimrunner::TimeoutError: Timed out while waiting for serverlist. Is an X11 server running?

./spec/test_spec.rb:7:in `block (2 levels) in <top (required)>'

I installed MacVim because my installation of standard vim does not meet the necessary requirements. I've verified there is a plist in place that I believe launches XQuartz and I've also tried running the executable manually. test_spec includes a single test that simply calls vim = Vimrunner.start. I see MacVim launch, but the test immediately fails with the above error.

I'd appreciate any help in getting this set up. Thanks.

AndrewRadev commented 11 years ago

Hmm, this is definitely odd behavior. As an aside, you shouldn't need XQuartz if you have MacVim, I guess the error message is a bit misleading.

As to why this is happening, I don't have a Mac, so it's difficult for me to try and replicate the issue. @mudge, if you have the time, I would appreciate if you simply tried running the latest version of Vimrunner, to confirm if I haven't broken something with a recent update.

What you could do for starters is try to get a Vim server and client running manually. Try executing the following:

mvim --servername TEST

And then, in a different terminal, execute

vim --serverlist
mvim --serverlist

And let me know what both of these commands output. In that line of thoughts, please also tell me what which vim and which mvim output, it may be a case of two different Vim installations taking effect.

emilford commented 11 years ago

Thanks for the response...

If I run mvim --servername TEST, I see an instance of MacVim start. The output then is as follows:

$ vim --serverlist VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jan 13 2013 12:14:18) Unknown option argument: "--serverlist" More info with: "vim -h"

[~][1.9.3-p327] $ mvim --serverlist TEST

And then locations for vim and mvim are:

[~][1.9.3-p327] $ which vim /usr/local/bin/vim

[~][1.9.3-p327] $ which mvim /usr/local/bin/mvim

AndrewRadev commented 11 years ago

Strange, if the vim executable doesn't have the clientserver functionality, it should fall back to using mvim instead.

Could you try using Vimrunner.start_gvim instead of Vimrunner.start? If this works, then it's an issue of feature detection. In that case, I'd like you to use the vimrunner command in your shell to open an irb console and execute:

Vimrunner::Platform.send :mac?

Just in case it turns out the configuration is getting confused for some reason.

Also, please paste the output of vim --version and mvim --version, maybe the compilation flags are not quite what the code assumes them to be.

emilford commented 11 years ago

I get the same outcome with Vimrunner.start_gvim.

Here is the requested output:

$ irb irb(main):001:0> require "bundler/setup" => true irb(main):002:0> require "vimrunner" => true irb(main):003:0> Vimrunner::Platform.send :mac? => 0 irb(main):004:0>

vim --version

$ vim --version VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jan 13 2013 12:14:18) MacOS X (unix) version Included patches: 1-762 Compiled by Eric@Erics-MacBook-Air.local Huge version without GUI. Features included (+) or not (-): +arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent -clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape +mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_sgr -mouse_sysmouse +mouse_urxvt +mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra -perl +persistent_undo +postscript +printer +profile +python -python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/local/share/vim" Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -no-cpp-precomp -Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.8 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang -L. -L/usr/local/lib -o vim -lm -lncurses -liconv -framework Cocoa -framework Python -lruby -lobjc

$ mvim --version VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 9 2013 18:51:57) MacOS X (unix) version Included patches: 1-754 Compiled by Eric@Erics-MacBook-Air.local Huge version with MacVim GUI. Features included (+) or not (-): +arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv -cscope +cursorbind +cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() +fullscreen -gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname +mouse +mouseshape +mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_sgr -mouse_sysmouse +mouse_urxvt +mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg +odbeditor +path_extra +perl +persistent_undo +postscript +printer +profile +python -python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white +tcl +terminfo +termresponse +textobjects +title +toolbar +transparency +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset +xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X_UNIX -no-cpp-precomp -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -I/System/Library/Frameworks/Tcl.framework/Headers -D_REENTRANT=1 -D_THREAD_SAFE=1 -D_DARWIN_C_SOURCE=1
Linking: clang -L. -L. -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon -lncurses -liconv -framework Cocoa -fstack-protector -L/usr/local/lib -L/System/Library/Perl/5.12/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -framework Python -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -framework Ruby

AndrewRadev commented 11 years ago

Output looks just like what I'd expect, so it should be skipping straight to mvim in the platform choice. Two more things:

Check the value of Vimrunner::Platform.vim and Vimrunner::Platform.gvim in the vimrunner console. Try executing Vimrunner.start('/usr/local/bin/mvim') instead of just Vimrunner.start.

emilford commented 11 years ago

Looks like it is...

$ irb irb(main):001:0> require "bundler/setup" => true irb(main):002:0> require "vimrunner" => true irb(main):003:0> Vimrunner::Platform.vim => "mvim" irb(main):004:0> Vimrunner::Plaform.gvim NameError: uninitialized constant Vimrunner::Plaform from (irb):4 from /usr/local/opt/rbenv/versions/1.9.3-p327/bin/irb:12:in `

' irb(main):005:0> Vimrunner::Platform.gvim
=> "mvim" irb(main):006:0>


 Failure/Error: vim = Vimrunner.start("/usr/local/bin/mvim")
 Vimrunner::TimeoutError:
   Timed out while waiting for serverlist. Is an X11 server running?
 # ./spec/test_spec.rb:7:in `block (2 levels) in <top (required)>'

Finished in 5.02 seconds 1 example, 1 failure

AndrewRadev commented 11 years ago

Alright, the only idea I have now is that the timeout is wonky for some reason. I've made the assumption that it should load in less than 5 seconds, but it might be slow or the timeout itself might be having some strange troubles.

I've pushed a branch called debug-issue-11. Could you check it out, run the bin/vimrunner executable and tell me what it outputs? Be prepared it might loop forever, so kill it after, say, 30-40 seconds, if you have to.

emilford commented 11 years ago

Waiting for serverlist. Current results: [ ]

^ That repeats continuously and eventually seems to hang. If I ctrl-c out of it, the following error occurs and MacVim is opened.

/Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner/server.rb:123:in sleep': Interrupt from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner/server.rb:123:inblock in wait_until_started' from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner/server.rb:119:in loop' from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner/server.rb:119:inwait_until_started' from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner/server.rb:56:in start' from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/lib/vimrunner.rb:49:instart_gvim' from /Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/bin/vimrunner:8:in <top (required)>' from bin/vimrunner:16:inload' from bin/vimrunner:16:in `

'

AndrewRadev commented 11 years ago

So it's not the timeout :). Let's try doing things manually, maybe something errors out while trying to start a server. Execute this in the shell:

mvim -f --servername VIMRUNNER0.12345 -u /path_to_vimrunner/vim/vimrc

Replacing path_to_vimrunner with the actual path to the source code. An mvim should start and you can run mvim --serverlist and check if VIMRUNNER0.12345 is in the output. If this works out just fine, it might be a PTY problem. in an irb, you can require 'pty' and run

PTY.spawn('mvim', '-f', '--servername', 'VIMRUNNER0.54321', '-u', '/path_to_vimrunner/vim/vimrc')

And then check the output of mvim --serverlist again

emilford commented 11 years ago

Hrm... looks like the problem is in my vimrc? I have no problems with these in standard vim. If this is in fact the issue, I'll have to see what's going on with the following settings:

$ mvim -f --servername VIMRUNNER0.12345 -u ~/Development/vest.vim/vendor/bundle/ruby/1.9.1/bundler/gems/vimrunner-1b9e3d982c24/vim/vimrc Error detected while processing /Users/Eric/.dotfiles/vim/plugin/settings/color_scheme.vim: line 4: E185: Cannot find color scheme 'solarized' Error detected while processing /Users/Eric/.dotfiles/vim/plugin/settings/tabular.vim: line 1: E492: Not an editor command: AddTabularPattern! colon /:/l1r0 line 2: E492: Not an editor command: AddTabularPattern! firstcolon /^[^:]\zs:/l1r0 line 3: E492: Not an editor command: AddTabularPattern! hash_rocket /=>/ line 4: E492: Not an editor command: AddTabularPattern! equals /=/ line 5: E492: Not an editor command: AddTabularPattern! firstequals /^[^=]\zs=/ line 6: E492: Not an editor command: AddTabularPattern! bar /|/l1r1 line 7: E492: Not an editor command: AddTabularPattern! first_singlequote /^[^']\zs'/l1c0 line 8: E492: Not an editor command: AddTabularPattern! first_doublequote /^[^"]\zs"/l1c0 line 9: E492: Not an editor command: AddTabularPattern! first_leftstash /^[^{]\zs{/ line 10: E492: Not an editor command: AddTabularPattern! first_rightstash /^[^}]\zs}/l1r0 line 11: E492: Not an editor command: AddTabularPattern! json /^[^:]*:\zs/l1r0

mudge commented 11 years ago

Quick heads up that I've tested the latest master version (37635de4a59e5a8e960bc127dedf00b77e4f79a0) against Ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin11.4.2] on Mac OS X 10.7.5 with Vim 7.3 (2010 Aug 15, compiled Jan 2 2012 17:38:47) and had no problems (all specs pass without issue).

One thing, my vim is actually a symlink to mvim:

lrwxr-xr-x  1 mudge  admin  19 26 Apr  2012 /usr/local/bin/vim -> /usr/local/bin/mvim

Eric, is your /usr/local/bin/vim a separate binary from mvim?

emilford commented 11 years ago

I'm not at my computer at the moment, but vim and mvim are separate and, I believe, are symlinked. They were both installed using Homebrew which I believe has that as the default behavior,

AndrewRadev commented 11 years ago

I think I got it -- the vimrc that is loaded is a very simple one, designed to provide a minimal collection of settings. However, it seems like your vim plugins are loaded regardless of the .vimrc. Which is perfectly obvious, now that I think about it -- the vimrc doesn't load stuff in your .vim directory, Vim does, because ~/.vim is in the runtimepath.

Oddly enough, I get similar errors, but it still loads for me, which means this might not be the core issue. Errors are errors, though, and should be fixed.

Anyway, long story short, I pushed a commit to master that excludes the ~/.vim directory from the runtimepath. Try it out and let me know if this fixes the issue, and if not, try out the previous debugging session and let me know what happens.

emilford commented 11 years ago

Hrm...the same error, unfortunately. I am able to run that previous command and an instance of MacVim launches. There's no error in console after the error, however, and I'm not returned to a prompt.

Running the PTY command gives the following output. I do not see anything in the server window nor anything obvious in the MacVim instance.

$ irb irb(main):001:0> require "pry" LoadError: cannot load such file -- pry from /usr/local/opt/rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require' from /usr/local/opt/rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:inrequire' from (irb):1 from /usr/local/opt/rbenv/versions/1.9.3-p327/bin/irb:12:in `

' irb(main):002:0> require "pty" => true irb(main):003:0> PTY.spawn('mvim', '-f', '--servername', 'VIMRUNNER0.54321', '-u', '/Users/Eric/Development/sweeter-vest.vim/vendor/bundle/ruby/1.9.1/gems/vimrunner-0.2.0/vim/vimrc') => [#File:/dev/ttys012, #File:/dev/ttys012, 34899]

AndrewRadev commented 11 years ago

The question is, however, when you run mvim -f --servername VIMRUNNER0.12345 -u /path_to_vimrunner/vim/vimrc, what does mvim --serverlist say? Same for the PTY line.

Also, could you post the output of :echo &runtimepath from within mvim? If you're still getting that error, maybe there's a specific runtimepath in mvim that I need to remove as well.

emilford commented 11 years ago

If I run...

$ mvim -f --servername VIMRUNNER0.12345 -u vendor/bundle/ruby/1.9.1/gems/vimrunner-0.2.0/vim/vimrc

I see a bunch of error output and do not get my prompt back. An instance of MacVim launches. I do now get a response on --serverlist

$ mvim --serverlist VIMRUNNER0.123452

PTY output...

$ irb rirb(main):001:0> require "pty" => true irb(main):002:0> PTY.spawn('mvim', '-f', '--servername', 'VIMRUNNER0.54321', '-u', '/Users/Eric/Development/vest.vim/vendor/bundle/ruby/1.9.1/gems/vimrunner-0.2.0/vim/vimrc') => [#File:/dev/ttys012, #File:/dev/ttys012, 98512]

But mvim--serverlist returns nothing.

AndrewRadev commented 11 years ago

Okay, so since the mvim is starting a server when run manually, but not when run through the PTY, I'm thinking maybe it really is the errors' fault, so we need to fix those first.

I've created a gist with a test vimrc file that might take care of the errors. Could you download it and try

mvim -u test_vimrc

(where "test_vimrc" is the downloaded file) And then tell me if you still get errors?

Also, could you post the contents of your runtimepath? You can get it by executing :echo &runtimepath within your mvim.

emilford commented 11 years ago

I received no errors launching mvim with the test vimrc.

runtimepath from inside vim launched with normal vimrc:

/Users/Eric/.vim/bundle/vundle,/Users/Eric/.vim/bundle/vim-colors-solarized,/Users/Eric/.vim/bundle/ctrlp.vim,/Users/Eric/.vim/bundle/vim-commentary,/Users/Eric/.vim/bundle/vim-rails,/Users/Eri c/.vim/bundle/vim-fugitive,/Users/Eric/.vim/bundle/tabular,/Users/Eric/.vim/bundle/vim-ruby,/Users/Eric/.vim/bundle/vim-surround,/Users/Eric/.vim/bundle/vim-repeat,/Users/Eric/.vim/bundle/gist- vim,/Users/Eric/.vim/bundle/webapi-vim,/Users/Eric/.vim/bundle/vim-endwise,/Users/Eric/.vim/bundle/supertab,/Users/Eric/.vim/bundle/vimux,/Users/Eric/.vim/bundle/vim-monokai,/Users/Eric/.vim/bu ndle/vim-coffee-script,/Users/Eric/.vim/bundle/syntastic,/Users/Eric/.vim/bundle/nerdtree,/Users/Eric/.vim/bundle/vim-instant-markdown,/Users/Eric/.vim/bundle/ack.vim,/Users/Eric/.vim/bundle/vi m-rake,/Users/Eric/.vim/bundle/gundo.vim,/Users/Eric/.vim/bundle/vim-speeddating,/Users/Eric/.vim/bundle/splitjoin.vim,/Users/Eric/.vim/bundle/sweeter-vest.vim,/Users/Eric/.vim,/usr/local/share /vim/vimfiles,/usr/local/share/vim/vim73,/usr/local/share/vim/vimfiles/after,/Users/Eric/.vim/after,/Users/Eric/.vim/bundle/vundle/,/Users/Eric/.vim/bundle/vundle/after,/Users/Eric/.vim/bundle/ vim-colors-solarized/after,/Users/Eric/.vim/bundle/ctrlp.vim/after,/Users/Eric/.vim/bundle/vim-commentary/after,/Users/Eric/.vim/bundle/vim-rails/after,/Users/Eric/.vim/bundle/vim-fugitive/afte r,/Users/Eric/.vim/bundle/tabular/after,/Users/Eric/.vim/bundle/vim-ruby/after,/Users/Eric/.vim/bundle/vim-surround/after,/Users/Eric/.vim/bundle/vim-repeat/after,/Users/Eric/.vim/bundle/gist-v im/after,/Users/Eric/.vim/bundle/webapi-vim/after,/Users/Eric/.vim/bundle/vim-endwise/after,/Users/Eric/.vim/bundle/supertab/after,/Users/Eric/.vim/bundle/vimux/after,/Users/Eric/.vim/bundle/vi m-monokai/after,/Users/Eric/.vim/bundle/vim-coffee-script/after,/Users/Eric/.vim/bundle/syntastic/after,/Users/Eric/.vim/bundle/nerdtree/after,/Users/Eric/.vim/bundle/vim-instant-markdown/after ,/Users/Eric/.vim/bundle/ack.vim/after,/Users/Eric/.vim/bundle/vim-rake/after,/Users/Eric/.vim/bundle/gundo.vim/after,/Users/Eric/.vim/bundle/vim-speeddating/after,/Users/Eric/.vim/bundle/split join.vim/after,/Users/Eric/.vim/bundle/sweeter-vest.vim/after

runtimepath from within mvim launched with test vimrc:

/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/vimfiles,/usr/ local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/runtime,/usr/local/ Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/vimfiles/after

AndrewRadev commented 11 years ago

I've pushed a new version of vimrunner, 0.2.1. Could you try it out and see if it fixes the issue?

emilford commented 11 years ago

I haven'r written anything extensive, but I was able to get a passing spec! Thanks for all the help! :thumbsup:

AndrewRadev commented 11 years ago

Glad I could solve the issue, sorry it took so long :). Happy testing.