ycm-core / YouCompleteMe

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

YCM freezes when using PHP method chaining in conjunction with closures #1728

Closed johnmaguire closed 9 years ago

johnmaguire commented 9 years ago

Proof of concept:

<?php

class Foobar {
    public function hello($var) {
        echo "Hello ";
        return $this;
    }

    public function world() {
        echo "World";
        return $this;
    }
}

$o = new Foobar();
$o->hello(function($var) use($asdf) {
    echo "closure";
})->

Start typing world at the end. As soon as you type "w" it will freeze.

Method chaining alone works fine (i.e. $o->hello()->world()), but when you pass a closure into one of the methods in the chain, YCM trips up.

johnmaguire commented 9 years ago
Error detected while processing function youcompleteme#Complete..<SNR>96_GetCompletions:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 3, in GetCompletionsInner
  File "/Users/jmaguire/.vim/plugged/YouCompleteMe/autoload/../python/ycm/client/omni_completion_request.py", line 30, in Start
    self._results = self._omni_completer.ComputeCandidates( self.request_data )
  File "/Users/jmaguire/.vim/plugged/YouCompleteMe/autoload/../python/ycm/omni_completer.py", line 60, in ComputeCandidates
    request_data )
  File "/Users/jmaguire/.vim/plugged/YouCompleteMe/autoload/../third_party/ycmd/ycmd/completers/completer.py", line 163, in ComputeCandidates
    candidates = self._GetCandidatesFromSubclass( request_data )
  File "/Users/jmaguire/.vim/plugged/YouCompleteMe/autoload/../third_party/ycmd/ycmd/completers/completer.py", line 179, in _GetCandidatesFromSubclass
    raw_completions = self.ComputeCandidatesInner( request_data )
  File "/Users/jmaguire/.vim/plugged/YouCompleteMe/autoload/../python/ycm/omni_completer.py", line 81, in ComputeCandidatesInner
    items = vim.eval( ''.join( omnifunc_call ) )
KeyboardInterrupt
micbou commented 9 years ago

Thanks for the report. Could you give us the output of the command :set omnifunc? in Vim? This is certainly an issue with the omnifunc function.

johnmaguire commented 9 years ago

Certainly. It reads omnifunc=phpcomplete#CompletePHP :)

vheon commented 9 years ago

@JohnMaguire what happen if you disable YCM and after typing the -> you type <C-X><C-O> in insert mode?

johnmaguire commented 9 years ago

Hopefully I understood you correctly. I ran :let g:ycm_auto_trigger=0, entered insert mode, put my cursor after -> and typed C-x C-o (X, O). Again, vim froze.

vheon commented 9 years ago

Then as I expected the problem is not in YCM but the omnifunc you're using is freezing vim. So here there is nothing we can do about it, so closing. Anyway in a comment of a related issue (https://github.com/Valloric/YouCompleteMe/issues/1548#issuecomment-146248076) someone suggested to use an updated version of the omnifunc for PHP (https://github.com/shawncplus/phpcomplete.vim). I don't know if it will help you or if you're already using it.

johnmaguire commented 9 years ago

@vheon Thank you very much for that link. The phpcomplete.vim plugin did indeed fix the issue. :+1: