Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.39k stars 128 forks source link

Bundle install problem when the directory has spaces (bundler: failed to load command: ruby-lsp) #852

Closed AsherWright closed 10 months ago

AsherWright commented 11 months ago

Ruby version

3.2.2

Code snippet

No response

Description

  1. Install the VSCode extension (Ruby LSP)
  2. Close VSCode
  3. Make your project directory have a space somewhere (e.g. /Users/Asher/Directory with spaces/project/.ruby-lsp/Gemfile.lock
  4. Open VSCode
  5. Get something like this:
Ruby LSP> Skipping custom bundle setup since /Users/asher/Local Documents/GitHub/chow/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using rake 13.0.6
...
Using rails 7.0.5
Bundler attempted to update ruby-lsp but its version stayed the same
Bundle updated!
bundler: failed to load command: ruby-lsp (/Users/asher/.rbenv/versions/3.2.2/bin/ruby-lsp)
/Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): "file:///Users/asher/Local Documents/GitHub/chow" (URI::InvalidURIError)
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/uri/rfc3986_parser.rb:71:in `parse'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/uri/common.rb:193:in `parse'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/uri/common.rb:722:in `URI'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.7.6/lib/ruby_lsp/utils.rb:9:in `<module:RubyLsp>'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.7.6/lib/ruby_lsp/utils.rb:4:in `<top (required)>'
    from <internal:/Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/Users/asher/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.7.6/lib/ruby_lsp/internal.rb:12:in `<top (required)>'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.7.6/exe/ruby-lsp:39:in `require_relative'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.7.6/exe/ruby-lsp:39:in `<top (required)>'
    from /Users/asher/.rbenv/versions/3.2.2/bin/ruby-lsp:25:in `load'
    from /Users/asher/.rbenv/versions/3.2.2/bin/ruby-lsp:25:in `<top (required)>'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:58:in `load'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:23:in `run'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli.rb:492:in `exec'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli.rb:34:in `dispatch'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/cli.rb:28:in `start'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/exe/bundle:37:in `block in <top (required)>'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /Users/asher/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.14/exe/bundle:29:in `<top (required)>'
    from /Users/asher/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
    from /Users/asher/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'
[Error - 3:04:50 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 3:04:50 PM] Connection to server got closed. Server will restart.
true
[Error - 3:04:50 PM] Ruby LSP client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097

It appears to be happening on this line.

Let me know

Expected output

A working installation, even if the directory has spaces in it. Let me know if this is unrealistic and any directories using ruby-lsp have to have no spaces.

oliwoodsuk commented 11 months ago

Getting the same error response too. I don't think we have a directory name with spaces in though. Did upgrade Ruby to 3.2.0 last week though.

...
Using requestjs-rails 0.0.9
Bundler attempted to update ruby-lsp but its version stayed the same
Bundler attempted to update debug but its version stayed the same
Bundle updated!
/Users/oli/.rvm/gems/ruby-3.2.0/gems/bundler-2.3.24/lib/bundler/definition.rb:507:in `materialize': Could not find rails-7.0.4, puma-5.6.5, uglifier-4.2.0, terser-1.1.12, pg-1.4.4, coffee-rails-4.2.2, turbo-rails-1.0.1, requestjs-rails-0.0.9, jbuilder-2.11.5, sprockets-4.2.0, sprockets-rails-3.4.2, jsbundling-rails-1.1.1, clearance-2.6.1, image_processing-1.12.2, inline_svg-1.8.0, mailgun-ruby-1.1.11, liquid-5.2.0, sidekiq-6.5.5, sidekiq-scheduler-4.0.3, sidekiq-throttled-0.18.0, redis-5.0.6, bootsnap-1.13.0, rexml-3.2.5, dotenv-rails-2.8.1, web-console-4.2.0, sqlite3-1.5.3, listen-3.7.1, spring-4.1.0, spring-watcher-listen-2.1.0, brakeman-5.3.1, non-stupid-digest-assets-1.0.9, capybara-3.39.2, selenium-webdriver-4.11.0, webmock-3.18.1, vcr-6.1.0, timecop-0.9.6, stimulus-rails-1.1.0, rake-13.0.6, daemons-1.4.1, aws-sdk-s3-1.132.0, shopify_app-18.1.3, shopify_api-9.5.1, view_component-2.74.1, httparty-0.20.0, hashie-5.0.0, chartkick-5.0.1, groupdate-6.2.0, rack-cors-2.0.1, rack-attack-6.6.1, cloudinary-1.23.0, amplitude-api-0.4.2, june-analytics-ruby-2.4.3, tailwindcss-rails-2.0.29-arm64-darwin, activerecord_json_validator-2.1.5, ruby-lsp-0.7.6, debug-1.8.0, actioncable-7.0.4, actionmailbox-7.0.4, actionmailer-7.0.4, actionpack-7.0.4, actiontext-7.0.4, actionview-7.0.4, activejob-7.0.4, activemodel-7.0.4, activerecord-7.0.4, activestorage-7.0.4, activesupport-7.0.4, railties-7.0.4, nio4r-2.5.8, execjs-2.8.1, coffee-script-2.4.1, concurrent-ruby-1.1.10, rack-2.2.4, argon2-2.1.1, bcrypt-3.1.18, email_validator-2.2.3, mini_magick-4.11.0, ruby-vips-2.1.4, nokogiri-1.13.8, rest-client-2.0.2, connection_pool-2.3.0, rufus-scheduler-3.8.2, tilt-2.0.11, redis-prescription-2.6.0, redis-client-0.14.1, msgpack-1.6.0, dotenv-2.8.1, bindex-0.8.1, mini_portile2-2.8.0, rb-fsevent-0.11.2, rb-inotify-0.10.1, addressable-2.8.1, matrix-0.4.2, mini_mime-1.1.2, rack-test-2.0.2, regexp_parser-2.6.0, xpath-3.2.0, rubyzip-2.3.2, websocket-1.2.9, crack-0.4.5, hashdiff-1.0.1, aws-sdk-core-3.180.0, aws-sdk-kms-1.71.0, aws-sigv4-1.6.0, browser_sniffer-2.2.0, jwt-2.7.0, omniauth-rails_csrf_protection-1.0.1, omniauth-shopify-oauth2-2.3.2, redirect_safely-1.0.0, activeresource-6.0.0, graphql-client-0.18.0, method_source-1.0.0, mime-types-3.4.1, multi_xml-0.6.0, aws_cf_signer-0.1.3, faraday-2.6.0, json_schemer-0.2.25, language_server-protocol-3.17.0.3, sorbet-runtime-0.5.10950, syntax_tree-6.1.1, irb-1.7.4, reline-0.3.7, websocket-driver-0.7.5, mail-2.7.1, net-imap-0.3.1, net-pop-0.1.2, net-smtp-0.3.2, rails-dom-testing-2.0.3, rails-html-sanitizer-1.4.3, globalid-1.0.0, builder-3.2.4, erubi-1.11.0, marcel-1.0.2, i18n-1.12.0, minitest-5.16.3, tzinfo-2.0.5, thor-1.2.1, zeitwerk-2.6.1, coffee-script-source-1.12.2, ffi-1.15.5, ffi-compiler-1.0.1, racc-1.6.0, http-cookie-1.0.5, netrc-0.11.0, fugit-1.8.1, public_suffix-5.0.0, aws-eventstream-1.2.0, aws-partitions-1.794.0, jmespath-1.6.2, omniauth-2.1.1, omniauth-oauth2-1.8.0, activemodel-serializers-xml-1.0.2, graphql-2.0.14, mime-types-data-3.2022.0105, faraday-net_http-3.0.1, ecma-re-validator-0.4.0, hana-1.3.7, simpleidn-0.2.1, uri_template-0.7.0, prettier_print-1.2.1, websocket-extensions-0.1.5, net-protocol-0.1.3, loofah-2.19.0, domain_name-0.5.20190701, et-orbi-1.2.7, raabro-1.4.0, rack-protection-3.0.6, oauth2-2.0.9, unf-0.1.4, timeout-0.3.0, crass-1.0.6, snaky_hash-2.0.1, version_gem-1.1.2, unf_ext-0.0.8.2 in locally installed gems (Bundler::GemNotFound)
    from <internal:/Users/Xxx/.rvm/rubies/ruby-3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/Xxx/.rvm/rubies/ruby-3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
[Error - 09:11:06] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

I manually bundle updated from the .ruby-lsp folder. Did have a weird Puma issue, but fixed it and did get a successful bundle reinstall. Same issue again though once I re-start VS Code.

richjdsmith commented 10 months ago

I am getting the same error as well. Mine appears to be calling bundler-1.17.2, despite 2.4.18 being set as my gem default.

...
bundler (2.4.18, default: 2.4.17, 2.4.14, 2.4.7, 2.2.32, 2.2.15, 1.17.2)
...
...
[Error - 10:08:21 AM] Starting client failed
/home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/shared_helpers.rb:272:in `search_up': undefined method `untaint' for "/home/richsmith/workspace/exonio":String (NoMethodError)

      current  = File.expand_path(SharedHelpers.pwd).untaint
                                                    ^^^^^^^^
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/shared_helpers.rb:259:in `find_file'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/shared_helpers.rb:251:in `find_gemfile'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/shared_helpers.rb:27:in `root'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler.rb:234:in `root'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler.rb:246:in `app_config_path'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler.rb:273:in `settings'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/feature_flag.rb:21:in `block in settings_method'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/cli.rb:97:in `<class:CLI>'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/cli.rb:7:in `<module:Bundler>'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/cli.rb:6:in `<top (required)>'
    from <internal:/home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
    from <internal:/home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/exe/bundle:23:in `block in <top (required)>'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/bin/bundle:25:in `load'
    from /home/richsmith/.asdf/installs/ruby/3.2.0/bin/bundle:25:in `<main>'
...
vinistock commented 10 months ago

@oliwoodsuk I don't believe your problem is related to this issue - especially given you mentioned there are no spaces in the path. There's already a PR to fix this issue, so can you please open a different one?

It looks like something might be wrong with the custom bundle configuration given that it succeeded in running bundle update, but somehow still didn't find installed gems. Please include information about your bundler configuration in the issue (e.g.: are you configuring BUNDLE_PATH?).

@richjdsmith your issue also seems to be unrelated. The custom bundle logic copies your application's Gemfile.lock in order to build a bundle including the ruby-lsp. Did you check what the locked bundler version is? If it's locked to 1.17.2, please update the bundler version lock (bundle update --bundler). If that's not the case, please open a different issue explaining your setup.

richjdsmith commented 10 months ago

Hey @vinistock, my mistake! running bundle update --bundler solved my issue - you are correct, the Gemfile.lock was stuck on version 1.17.2

Thanks for your help and sorry for the inconvenience!

AsherWright commented 10 months ago

Thanks for the fix @vinistock :)

vinistock commented 10 months ago

My pleasure!