rubycomplete fails to complete objects starting with "c" #103

Open
geraldh opened this Issue Aug 17, 2012 · 1 comment

Comments

Projects
None yet
2 participants

geraldh commented Aug 17, 2012

Hello -- this was driving me nuts:

class Ctest
  def initialize(id)
    @id = id
  end
end
c = C<C-X><C-O>
Error detected while processing function rubycomplete#Complete:
line   22:
ArgumentError: comparison of Hash with Hash failed

Changing the class name to Dtest makes it possible to omnicomplete "D".
It turns out that the rubycomplete.vim has problems with ruby-1.9.3

  • Fedora 17 (vim-7.3.556 ruby-1.9.3) fails
  • Ubuntu 12.04 (vim-7.3.429 ruby-1.8.7) works

After some debbuging of rubycomplete.vim, I found the problem was raised by the sort! method in the following block in method get_completions(base)

    valid = []
    valid += methods.collect { |m| { :name => m, :type => 'm' } }
    valid += variables.collect { |v| { :name => v, :type => 'v' } }
    valid += classes.collect { |c| { :name => c, :type => 't' } }
    valid += constants.collect { |d| { :name => d, :type => 'd' } }
    valid.sort! { |x,y| x[:name] <=> y[:name] }

If you try to omnicomplete "'C" - the value array contains a Symbol :Complex

{:name=>:Complex, :type=>"m"}

which borks in value.sort! -- Changing this block to:

    valid = []
    valid += methods.collect { |m| { :name => m.to_s, :type => 'm' } }
    valid += variables.collect { |v| { :name => v.to_s, :type => 'v' } }
    valid += classes.collect { |c| { :name => c.to_s, :type => 't' } }
    valid += constants.collect { |d| { :name => d.to_s, :type => 'd' } }
    valid.sort! { |x,y| x[:name] <=> y[:name] }

makes the completion work on ruby-1.9.3

Please fix rubycomplete.vim

Member

AndrewRadev commented Nov 13, 2012

You're right, this does fix the issue. I assume the problem is that some of the keys are strings and others are symbols, and using <=> on a symbol and a string returns nil in my console. Turning them into symbols with to_sym would also work, but strings seem fine in this case (they're probably to_s-ed later anyway).

Sorry for the late reply. I've pushed your fix to master. Could you confirm this fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment