Shopify / ruby-lsp-rails

A Ruby LSP add-on for Rails
https://shopify.github.io/ruby-lsp/rails-add-on
MIT License
581 stars 27 forks source link

Undefined method `source_location` for `ActionDispatch::Journey::Route` with Rails 6.1 #492

Closed srpouyet closed 1 month ago

srpouyet commented 1 month ago

Hi,

First, thanks for ruby-lsp and ruby-lsp-rails! It really enhances the ruby VSCode experience ✨

When running ruby-lsp-rails (version 0.3.20) with a rails 6.1 app, the addon calls ActionDispatch::Journey::Route#source_location. However, it seems like that source_location is not (yet) defined in rails 6.1, which leads to this NoMethodError popping up in the extension's output:

2024-10-23 10:36:23.659 [info] (app) Initializing Ruby LSP v0.20.1...
2024-10-23 10:36:23.667 [info] (app) Auto detected formatter: rubocop
2024-10-23 10:36:23.668 [info] (app) Auto detected linters: rubocop
2024-10-23 10:36:23.668 [info] (app) Detected test library: rspec
2024-10-23 10:36:23.668 [info] (app) Finished initializing Ruby LSP!
2024-10-23 10:36:24.079 [info] (app) Activating Ruby LSP Rails add-on v0.3.20
2024-10-23 10:36:24.079 [info] (app) Ruby LSP Rails booting server
2024-10-23 10:36:26.677 [info] (app) Finished booting Ruby LSP Rails server
2024-10-23 10:36:55.608 [info] (app) Running via Spring preloader in process 110662
2024-10-23 10:36:55.608 [info] (app) Request  failed:
2024-10-23 10:36:55.608 [info] (app) /usr/local/bundle/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:149:in 'resolve_route_info': undefined method 'source_location' for #<ActionDispatch::Journey::Route:0x0000ffff91eec320 @name="graphql", # removed internal state for brevity
2024-10-23 10:36:55.609 [info] (app) 
2024-10-23 10:36:55.609 [info] (app)         if route&.source_location
2024-10-23 10:36:55.609 [info] (app)                 ^^^^^^^^^^^^^^^^^
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:117:in 'execute'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:100:in 'start'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:252:in '<main>'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/railties-6.1.7.9/lib/rails/commands/runner/runner_command.rb:42:in 'load'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/railties-6.1.7.9/lib/rails/commands/runner/runner_command.rb:42:in 'perform'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/thor-1.3.2/lib/thor/command.rb:28:in 'run'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'invoke_command'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/thor-1.3.2/lib/thor.rb:538:in 'dispatch'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/railties-6.1.7.9/lib/rails/command/base.rb:69:in 'perform'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/railties-6.1.7.9/lib/rails/command.rb:48:in 'invoke'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/railties-6.1.7.9/lib/rails/commands.rb:18:in '<main>'
2024-10-23 10:36:55.609 [info] (app)  from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in 'require'
2024-10-23 10:36:55.609 [info] (app)  from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in 'require'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'require'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in 'require'
2024-10-23 10:36:55.609 [info] (app)  from /app/bin/rails:13:in '<main>'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/commands/rails.rb:6:in 'load'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/commands/rails.rb:6:in 'call'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/commands/rails.rb:51:in 'call'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/command_wrapper.rb:38:in 'call'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application.rb:221:in 'block in serve'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:10:in 'block in fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:10:in 'block in fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:8:in 'fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:8:in 'fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:27:in 'fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:8:in 'fork'
2024-10-23 10:36:55.609 [info] (app)  from /usr/local/bundle/gems/activesupport-6.1.7.9/lib/active_support/fork_tracker.rb:27:in 'fork'
2024-10-23 10:36:55.610 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application.rb:185:in 'serve'
2024-10-23 10:36:55.610 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application.rb:148:in 'block in run'
2024-10-23 10:36:55.610 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application.rb:142:in 'loop'
2024-10-23 10:36:55.610 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application.rb:142:in 'run'
2024-10-23 10:36:55.610 [info] (app)  from /usr/local/bundle/gems/spring-4.1.2/lib/spring/application/boot.rb:19:in '<top (required)>'
2024-10-23 10:36:55.610 [info] (app)  from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in 'require'
2024-10-23 10:36:55.610 [info] (app)  from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in 'require'
2024-10-23 10:36:55.610 [info] (app)  from -e:1:in '<main>'

(Hopefully correctly) verifying that the method is undefined in pry:

[2] pry(main)> $ ActionDispatch::Journey::Route#source_location
Error: Couldn't locate a definition for ActionDispatch::Journey::Route#source_location
breiko83 commented 1 month ago

Having the same issue since the last update. I'm on Ruby 3.3.4 Rails 7.0.8.5

2024-10-23 12:11:25.752 [info] (app) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle _2.3.12_ check || bundle _2.3.12_ install) 1>&2
2024-10-23 12:11:26.337 [info] (app) The Gemfile's dependencies are satisfied
2024-10-23 12:11:27.825 [info] (app) Initializing Ruby LSP v0.20.1...
2024-10-23 12:11:27.831 [info] (app) Using formatter specified by user: rubocop
2024-10-23 12:11:27.831 [info] (app) Auto detected linters: rubocop
2024-10-23 12:11:27.831 [info] (app) Detected test library: rspec
2024-10-23 12:11:27.831 [info] (app) Finished initializing Ruby LSP!
2024-10-23 12:11:28.300 [info] (app) Activating Ruby LSP Rails add-on v0.3.20
2024-10-23 12:11:28.309 [info] (app) Ruby LSP Rails booting server
2024-10-23 12:11:35.083 [info] (app) Finished booting Ruby LSP Rails server
2024-10-23 12:26:29.367 [info] (app) Request  failed:
2024-10-23 12:26:29.367 [info] (app) /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:149:in `resolve_route_info': undefined method `source_location' for an instance of ActionDispatch::Journey::Route (NoMethodError)
2024-10-23 12:26:29.367 [info] (app) 
2024-10-23 12:26:29.367 [info] (app)         if route&.source_location
2024-10-23 12:26:29.367 [info] (app)                 ^^^^^^^^^^^^^^^^^
2024-10-23 12:26:29.367 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:117:in `execute'
2024-10-23 12:26:29.367 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:100:in `start'
2024-10-23 12:26:29.367 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:252:in `<top (required)>'
2024-10-23 12:26:29.367 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.0.8.5/lib/rails/commands/runner/runner_command.rb:43:in `load'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.0.8.5/lib/rails/commands/runner/runner_command.rb:43:in `perform'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.0.8.5/lib/rails/command/base.rb:87:in `perform'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.0.8.5/lib/rails/command.rb:48:in `invoke'
2024-10-23 12:26:29.368 [info] (app)    from /Users/breiko83/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/railties-7.0.8.5/lib/rails/commands.rb:18:in `<top (required)>'
2024-10-23 12:26:29.368 [info] (app)    from bin/rails:4:in `require'
2024-10-23 12:26:29.368 [info] (app)    from bin/rails:4:in `<main>'
flemaitre33 commented 1 month ago

+1 Having the same issue with Ruby 3.0.6 and Rails 6.1

2024-10-23 14:36:44.579 [info] (quipuapp) /usr/lib/fullstaq-ruby/versions/3.0.6-jemalloc/lib/ruby/gems/3.0.0/gems/ruby-lsp-rails-0.3.20/lib/ruby_lsp/ruby_lsp_rails/server.rb:149:in `resolve_route_info': undefined method `source_location' for 
#(NoMethodError)
vinistock commented 1 month ago

Thank you for the bug report! There's a PR open to fix it #489, just waiting on reviews.