dgutov / robe

Code navigation, documentation lookup and completion for Ruby
584 stars 37 forks source link

More automation/clearer instructions on setting up load path #107

Closed sambrightman closed 5 years ago

sambrightman commented 7 years ago

It wasn't really clear to me how to get everything setup right from the README (certainly it did not work out-of-the-box from following those instructions, although my target project was perhaps also a little abnormal). Example: I have to manually require the source file in the pry buffer before goto definition will work - is this intentional/known? Also, in my case the project lacked a Gemfile so I had to add one for pry (which mentioned in the README) and ensure this was at the top:

lib = File.expand_path('../path/to/lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

is this intentionally manual, or is purely due to lacking a lib directory? I'd think the setup code could ensure the parent directory of the file in question was in the load path and loaded.

dgutov commented 7 years ago

From the README:

uses a Ruby REPL subprocess with your application or gem code loaded

How would you phrase it better?

dgutov commented 7 years ago

The exact setup code depends on the application. Especially when it's unusual, like in your case.

sambrightman commented 7 years ago

If I follow all of the instructions - even with my Gemfile manually added - and then try to go to definition I just get an error. Is there a project setup where this would not be the case?

It seems like even if I had not had to do my own load path manipulation, and applied all of the init.el steps in the README for automatic setup, I would still have got "Method not found". Have I misunderstood? If not, then it would probably make sense to distinguish between the fact that robe automatically starts itself and inferior process buffer, and the fact that it doesn't automatically load your code.

dgutov commented 7 years ago

Is there a project setup where this would not be the case?

Sure. A simple Rails project, for example. Or a traditionally-structured gem. Both are well-supported by inf-ruby-console-auto.

sambrightman commented 7 years ago

I just tried cloning thor and json gems, opening a random ruby file in emacs and going to definition. It was not able to start Robe. I tried again without opening the file directly, first running rvm-use and selecting the gemset which I had run bundle install in, and then opening a file. Again, not able to start Robe. I keep trying to assume that this is my lack of knowledge about the Ruby ecosystem, or a problem with RVM. I try again using RVM on the command line before running emacs. Still an error. I try gem install of pry etc. into the default gemset in case the gemset is not being selected correctly. This allows Robe to start. Go to method/class still fails. If I already know the target file, I can manually go there and load the file into the server, then it finally works.

My question is: how much of this manual setup is known/intentional? If there are parts that are missing from the README, they could be added to save time in setup. Perhaps you can give an example of how you get go-to-definition working for the json gem starting with emacs -q?

This comment: https://github.com/dgutov/robe/issues/107#issuecomment-330372192 suggest that you intend for people to manually load files into the server. Is that right? I find that surprising, because it would not be the norm for an IDE-like experience. Could Robe automatically load files in?

dgutov commented 7 years ago

Again, not able to start Robe

Details?

Still an error

Which one?

sambrightman commented 7 years ago

In this case most initial errors were Robe launch failed, perhaps due to combinations of not finding the right environment, not having pry available in the right places etc. I'm not really sure at this stage whether I'm doing something wrong or whether they are unexpected bugs. Point being, even after I've got past that: goto definition still fails to find methods etc.

That's why I'm asking which parts are expected to work automatically. Maybe it's simpler to show a working example for a standard gem as you suggested? What steps do you take from git clone of the gem?

dgutov commented 7 years ago

It should be easier for me to address your problems. And then, hopefully, you could produce the "clearer instructions" you wished you had. Or at least give a rough first version.

sambrightman commented 7 years ago

Here are my steps:

Surely none of this is wrong?

Cloning into 'json'...
remote: Counting objects: 6345, done.
remote: Total 6345 (delta 0), reused 0 (delta 0), pack-reused 6345
Receiving objects: 100% (6345/6345), 3.25 MiB | 1.13 MiB/s, done.
Resolving deltas: 100% (3419/3419), done.
()[sam@HMs-MacBook-Air dev]$ cd json
()[sam@HMs-MacBook-Air json (master=)]$ rvm gemset create json
Can not create gemset when using system ruby.  Try 'rvm use <some ruby>' first.
()[sam@HMs-MacBook-Air json (master=)]$ rvm use default
Using /Users/sam/.rvm/gems/ruby-2.2.0
(ruby-2.2.0)[sam@HMs-MacBook-Air json (master=)]$ rvm gemset create json
ruby-2.2.0 - #gemset created /Users/sam/.rvm/gems/ruby-2.2.0@json
ruby-2.2.0 - #generating json wrappers........
()[sam@HMs-MacBook-Air json (master=)]$ rvm gemset use json
Using ruby-2.2.0 with gemset json
(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master=)]$ gem install bundler
Successfully installed bundler-1.15.4
Parsing documentation for bundler-1.15.4
Done installing documentation for bundler after 4 seconds
1 gem installed
(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master=)]$ bundle install
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.1.0
Using bundler 1.15.4
Using json 2.1.0 from source at `.`
Using test-unit 2.5.5
Bundle complete! 3 Gemfile dependencies, 4 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master=)]$ emacs lib/json/pure/parser.rb

I hit M-. on a function or class name and get this error:

/Users/sam/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 14 total gem(s) (G\
em::LoadError)
Checked in 'GEM_PATH=/Users/sam/.rvm/gems/ruby-2.2.0:/Users/sam/.rvm/gems/ruby-2.2.0@global', execute `gem env` for more information
    from /Users/sam/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
    from /Users/sam/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /Users/sam/.rvm/gems/ruby-2.2.0@json/bin/bundle:22:in `<main>'
    from /Users/sam/.rvm/gems/ruby-2.2.0@global/bin/ruby_executable_hooks:15:in `eval'
    from /Users/sam/.rvm/gems/ruby-2.2.0@global/bin/ruby_executable_hooks:15:in `<main>'

Process gem exited abnormally with code 1

Figured out how to workaround but unsure if intended

I try M-x rvm-use RET json RET inside Emacs and get the same error when hitting M-.. I have no clue why it is not findingbundler (I also have the devadvice from the README), so in pure hope I do M-x rvm-gem-install bundler. It fixes something, because trying M-. again gives:

Could not find rake-12.1.0 in any of the sources
Run `bundle install` to install missing gems.

Process gem exited abnormally with code 7

Rake just got installed! So I now suspect it's ignoring the json gemset and picking up an old version from global (mentioned in the log above):

(ruby-2.2.0)[sam@HMs-MacBook-Air json (master=)]$ rvm gemset use global
Using ruby-2.2.0 with gemset global
(ruby-2.2.0@global)[sam@HMs-MacBook-Air json (master=)]$ bundle update
bash: bundle: command not found

Hmmph. Maybe default?

(ruby-2.2.0@global)[sam@HMs-MacBook-Air json (master=)]$ rvm gemset use default
Using ruby-2.2.0 with gemset default
(ruby-2.2.0)[sam@HMs-MacBook-Air json (master=)]$ bundle update
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Fetching rake 12.1.0
Installing rake 12.1.0
Using bundler 1.15.4
Using json 2.1.0 from source at `.`
Fetching test-unit 2.5.5
Installing test-unit 2.5.5
Bundle updated!
(ruby-2.2.0)[sam@HMs-MacBook-Air json (master=)]$ rvm gemset use json
Using ruby-2.2.0 with gemset json
(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master *=)]$

Try again:

2.2.0 :001 > LoadError: cannot load such file -- pry
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe/sash/doc_for.rb:1:in `require'
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe/sash/doc_for.rb:1:in `<top (required)>'
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe/sash.rb:1:in `require'
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe/sash.rb:1:in `<top (required)>'
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe.rb:1:in `require'
    from /Users/sam/dev/dotfiles/.emacs.d/.cask/25.3/elpa/robe-20170611.1755/lib/robe.rb:1:in `<top (required)>'
    from (irb):1:in `require'
    from (irb):1
    from /Users/sam/.rvm/rubies/ruby-2.2.0/bin/irb:11:in `<top (required)>'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `load'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `kernel_load'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:27:in `run'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli.rb:362:in `exec'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/exe/bundle:30:in `block in <top (required)>'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
    from /Users/sam/.rvm/gems/ruby-2.2.0/gems/bundler-1.15.4/exe/bundle:22:in `<top (required)>'
    from /Users/sam/.rvm/gems/ruby-2.2.0/bin/bundle:23:in `load'
    from /Users/sam/.rvm/gems/ruby-2.2.0/bin/bundle:23:in `<main>'
    from /Users/sam/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/sam/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'2.2.0 :002 >

Aha! At least somewhat expected - I add pry and pry-doc to Gemfile:

(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master *=)]$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/.
Using rake 12.1.0
Using bundler 1.15.4
Fetching coderay 1.1.2
Installing coderay 1.1.2
Using json 2.1.0 from source at `.`
Fetching method_source 0.8.2
Installing method_source 0.8.2
Fetching slop 3.6.0
Installing slop 3.6.0
Fetching yard 0.9.9
Installing yard 0.9.9
Using test-unit 2.5.5
Fetching pry 0.10.4
Installing pry 0.10.4
Fetching pry-doc 0.11.1
Installing pry-doc 0.11.1
Bundle complete! 5 Gemfile dependencies, 10 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from yard:
--------------------------------------------------------------------------------
As of YARD v0.9.2:

RubyGems "--document=yri,yard" hooks are now supported. You can auto-configure
YARD to automatically build the yri index for installed gems by typing:

    $ yard config --gem-install-yri

See `yard config --help` for more information on RubyGems install hooks.

You can also add the following to your .gemspec to have YARD document your gem
on install:

    spec.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.

--------------------------------------------------------------------------------

Try again:

Could not find coderay-1.1.2 in any of the sources
Run `bundle install` to install missing gems.

Process gem exited abnormally with code 7

No dice. What happened?

(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master *=)]$ gem list | grep coderay
coderay (1.1.2)

Okay, getting pretty ridiculous, maybe I totally misunderstand gemsets so let's forget about it and use default for everything:

(ruby-2.2.0@json)[sam@HMs-MacBook-Air json (master=)]$ rvm gemset use default
Using ruby-2.2.0 with gemset default
(ruby-2.2.0)[sam@HMs-MacBook-Air json (master *=)]$ bundle install
...

M-.:

Can’t find the location

Robe is up! But no goto-definition. There has been some suggestion that I have to manually load a file before being able to use Robe with it... C-c C-l RET M-.. Works!

Summary

Maybe a lot of this is misunderstanding, maybe some of it is the fault of rvm.el or inf-ruby. I hope you can understand how frustrating this is though. It certainly feels like it could be smoother/more automated, or that different workflows could be outlined in README.

dgutov commented 7 years ago

@sambrightman Thank you. But as you can see, most of the difficulty in this scenario stems from your use of RVM. I don't use it, so I can't debug this, or write the step-by-step instruction.

Using rbenv, you just don't see these kinds of problems. At least on Ubuntu, you put its setup into ~/.profile, re-login, and it works in Emacs as well as everywhere else.

The only thing left in your scenario will be adding pry to Gemfile (pry-doc is optional). Which is indeed documented. And running bundle install, of course.

dgutov commented 7 years ago

@dgtized Any idea why your defadvice doesn't help here?

dgutov commented 7 years ago

@sambrightman

Robe is up! But no goto-definition. There has been some suggestion that I have to manually load a file

Not in this case, though. For https://github.com/flori/json, inf-ruby-console-auto correctly calls inf-ruby-console-gem, and navigation works just fine.

It might be different depending on how you create the REPL buffer. There is no information about that in your steps.

dgtized commented 7 years ago

Unfortunately I've switched from RVM to chruby. I still have the corresponding defadvice but updated for chruby, but I'm not sure if that swap is advice is still required? I think all of my corresponding local config is here: https://github.com/dgtized/dotfiles/blob/master/site-lisp/clgc-ruby.el#L30-L45, so maybe something there to experiment with?

As an aside, previously, the lag time on company completions on the project I'm working on with robe enabled was too much to keep it active. But I just tested it out again after rechecking the setup (notably the eval-after-load hook on company mode), and it's working much nicer now! So thanks!

dgutov commented 7 years ago

think all of my corresponding local config is here

Thanks. I'll leave that to RVM users.

it's working much nicer now

If "previously" was two years ago or more, it might be from https://github.com/dgutov/robe/commit/378937d4ea50a235a633236598c46dab259790da or nearby commits. If not, I'd be surprised :)

dgutov commented 5 years ago

I don't think we'll ever find out what went wrong here. :confused:

sambrightman commented 5 years ago

It seemed to me that you weren't keen to improve things for RVM users at all (not even adding/incorporating some documentation/example config). Most of your responses seemed uncharitable or hostile to me.

dgutov commented 5 years ago

Sorry if I was abrupt at times, but one thing I didn't want to do is install RVM and go on and troubleshoot it step by step myself. The advice we already documented should take care of RVM integration, and if it doesn't, you are welcome to suggest better documentation. I never said I'm not going to incorporate it.

I do think the problem was somewhere either inside rvm.el (and then it should be reported there), or around your use of it (more likely). But even re-reading the discussion now, I'm not entirely sure which exact keys you typed and commands invoked aside from M-. (and describing those, step by step, is usually the norm in bug reporting). In particular, I don't see you mentioning any prompts, typing yes, etc.

So maybe things failed because you launched the REPL some other way than through inf-ruby-console-auto or robe-start (which calls the former function if there's no existing REPL buffer).