nonsequitur / inf-ruby

218 stars 69 forks source link

What could be causing autocomplete to fail #160

Closed jgomo3 closed 1 year ago

jgomo3 commented 2 years ago

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!

dgutov commented 2 years ago

Hi!

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

jgomo3 commented 2 years ago

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?

dgutov commented 2 years ago

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?

jgomo3 commented 2 years ago

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.

dgutov commented 2 years ago

require 'irb/completion' doesn't fail.

Does completion start to work after that?

jgomo3 commented 2 years ago

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.

dgutov commented 2 years ago

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).

jgomo3 commented 2 years ago

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.

dgutov commented 1 year ago

Let's reopen when we have more info.