castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
423 stars 25 forks source link

Solargraph incompatible with relative bundle path #196

Open vemek opened 3 years ago

vemek commented 3 years ago

I've noticed a minor issue using Solargraph with Bundler when Bundler is configured to install gems to somewhere other than the default path. Please correct me if there is a configuration option for this - although I would assume it should be picked up automatically.

I configure Bundler such that it stores gems in the directory of the various projects I'm working on. This may be unusual, but is a supported use case. Here's the config:

---
BUNDLE_PATH: ".bundle"

With this config, Solargraph fails to find the gem documentation:

...<snip>...
Documenting rails-html-sanitizer 1.3.0
rails-html-sanitizer 1.3.0 YARD documentation failed
Documenting actionview 6.0.3.3
actionview 6.0.3.3 YARD documentation failed
Documenting rack 2.2.3
rack 2.2.3 YARD documentation failed
Documenting rack-test 1.1.0
rack-test 1.1.0 YARD documentation failed
Documenting actionpack 6.0.3.3
actionpack 6.0.3.3 YARD documentation failed
Documenting websocket-extensions 0.1.5
websocket-extensions 0.1.5 YARD documentation failed
Documenting websocket-driver 0.7.3
websocket-driver 0.7.3 YARD documentation failed
Documenting actioncable 6.0.3.3
actioncable 6.0.3.3 YARD documentation failed
Documenting globalid 0.4.2
...<snip>...

Removing the Bundler config allows Solargraph to find the docs. I have not dug through the code to figure out how Solargraph builds the expected paths for these gems, but perhaps there is a way for it to interrogate Bundler about its config.

castwide commented 3 years ago

Is that the output from running solargraph bundle?

The first thing I'd check is if this is a permission issue, e.g., if the .bundle directory belongs to a different user.

Whatever the root cause, I'll update the documentation output to provide more detail about the error.

vemek commented 3 years ago

Sorry for the delay responding.

Is that the output from running solargraph bundle

Yes

The first thing I'd check is if this is a permission issue, e.g., if the .bundle directory belongs to a different user.

It belongs to my user. I've been testing different configurations, and it seems that solargraph requires all gems to be installed to the Rubygems path. Bundler also uses this path by default, but can be changed - a popular option is to install bundled gems to vendor/, for example. My opinion is that calling out this requirement somewhere in the docs would be helpful, and probably sufficient to unblock future users with similar configs from using solargraph. Support for different bundle paths would be great, but the effort may not be worth it for the small number of users likely affected.

justinhoward commented 3 years ago

I can reproduce this if I install solargraph globally (gem install solargraph), then run solargraph bundle on a project without using bundle exec. The reason I might want to do this is to avoid installing solargraph as a project dependency, but still use the BUNDLE_PATH feature.

After some digging into the source, I found that the issue is a discrepancy with what is listed in Documentor.specs_from_bundle and what is in the YARD::Registry.

I'm guessing that this happens because YARD assumes that all gems you are trying to document with yard gem are in your current gem path. It has no ability to list or operate on gems outside that. Since solargraph is operating in the global context (because I ran it with solargraph bundle), YARD operates in that same context. When I use bundle exec yard, I'm forcing YARD to use the bundler gem path, but that same hack doesn't work for YARD::Registry operating in the solargraph process.

justinhoward commented 3 years ago

Looks like this is likely the same issue as https://github.com/castwide/solargraph/issues/384 which has been closed.

Looking a bit deeper, I found that I was able to generate the yard documentation for my bundled gems if I had yard installed into my Gemfile, and ran bundle exec yard gems. However, even after that, solargraph wasn't able to detect those docs. I assume for the same reason as I explained above.

So, it seems this issue is larger than just the solargraph bundle command. Solargraph in general doesn't work for gems in BUNDLE_PATH unless solargraph itself is installed with bundler.

Maybe this is just an unsupported configuration, in which case there are two workarounds: