inf-ruby icon indicating copy to clipboard operation
inf-ruby copied to clipboard

What could be causing autocomplete to fail

Open jgomo3 opened this issue 3 years ago • 8 comments

I'm using rvm.el.

If I simply run the inferior ruby, autocomplet works.

If I rvm use something else in Emacs, then the inferior ruby will not give me autocomplete.

Do you have any hint that maybe could help me to find out what could be wrong?

Thanks!

jgomo3 avatar May 04 '22 20:05 jgomo3

Hi!

Perhaps rvm gives you a different version of Ruby and/or different version of Irb?

dgutov avatar May 05 '22 01:05 dgutov

Sure, rvm allows me to change Ruby versions. But digging in the idea that something is giving me something different... I narrowed the problem to the following:

The Problem

After setting a non default Ruby with rvm,

Getting the inferior Ruby IRB simply with M-x inf-ruby, the IRB autocompletes fine, and these are the versions of Ruby and IRB:

irb(main):001:0> RUBY_VERSION
=> "2.3.8"
irb(main):003:0> IRB.version
=> "irb 0.9.6(09/06/30)"
irb(main):004:0> 

BUT getting it using M-x inf-ruby-console-auto inside a particular Rails project, autocomplete fails with the message No matches. But the versions are reported to be the same:

irb(main):001:0> RUBY_VERSION
=> "2.3.8"
irb(main):002:0> IRB.version
=> "irb 0.9.6(09/06/30)"

But I tried the same experiment in other Ruby projects, with the same Ruby and IRB versions, and autocomplete just work.

So it must be something specific to my Rails project that is sabotaging the autocomplete in that inferior ruby.

If I would like to sabotage autocomplete in a project: What should I do? What should I be paying attention to?

jgomo3 avatar May 05 '22 21:05 jgomo3

Hmm. So it's not just IRB: inf-ruby-console-auto launches a project-specific REPL, which is most likely rails console.

What if you enter require 'irb/completion' in the latter REPL?

dgutov avatar May 06 '22 21:05 dgutov

Hi, thank you for the hints.

You are correct, the REPL should be rails console. At least the buffer name for the inferior ruby is *rails*.

require 'irb/completion' doesn't fail.

jgomo3 avatar May 09 '22 11:05 jgomo3

require 'irb/completion' doesn't fail.

Does completion start to work after that?

dgutov avatar May 09 '22 12:05 dgutov

require 'irb/completion' doesn't fail.

Does completion start to work after that?

Sorry, I didn't mention that, but no, the completion doesn't work after that.

Other things to notice:

If I run irb or rails console anywhere in my system, from Emacs shell (M-x shell) the autocompletion doesn't work neither. But, from bash in my terminal emulator (Guake, Gnome Terminal, etc.) it does work fine. For any version of Ruby using rvm manually.

jgomo3 avatar May 09 '22 13:05 jgomo3

You can try step-debuggin through inf-ruby-completions to see where (and whether) it fails. To find out how to do that, the web search keyword is edebug.

Or you can check out the Ruby expression that is formed with concatenation in the middle of that function. And call it in the REPL. The value of line is the full contents of the current line (excluding the prompt), and expr is either the same (for simple examples), or, if the line contains any char from the set in inf-ruby-ruby-expr-break-chars, the contents between the last such occurrence and point (the cursor).

dgutov avatar May 28 '22 23:05 dgutov

Thanks, so checking that Ruby expression you pointed, at first run it does works. Well, I have now where to dig. Thanks for pointing it out. If I found the problem, I'll let you know what was.

jgomo3 avatar May 30 '22 17:05 jgomo3

Let's reopen when we have more info.

dgutov avatar Oct 01 '23 12:10 dgutov