Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NoMethodError] undefined method `find_index' for nil:NilClass #323

Closed
aaronjensen opened this issue May 2, 2020 · 9 comments
Closed

[NoMethodError] undefined method `find_index' for nil:NilClass #323

aaronjensen opened this issue May 2, 2020 · 9 comments

Comments

@aaronjensen
Copy link

I'm getting this error when starting 0.39.5. I also got it with 0.39.3.

[WARN] Error processing request: [NoMethodError] undefined method `find_index' for nil:NilClass
[WARN] ~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:85:in `find_directive_line_number'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:70:in `block in process_comment'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:69:in `each'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:69:in `process_comment'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:192:in `block in process_comment_directives'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:189:in `each'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:189:in `process_comment_directives'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:27:in `map'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map/mapper.rb:50:in `map'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/source_map.rb:141:in `map'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/api_map.rb:88:in `block in catalog'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/api_map.rb:70:in `each'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/api_map.rb:70:in `catalog'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/library.rb:23:in `initialize'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/library.rb:363:in `new'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/library.rb:363:in `load'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/host.rb:278:in `prepare'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/host.rb:295:in `block in prepare_folders'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/host.rb:294:in `each'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/host.rb:294:in `prepare_folders'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/message/initialize.rb:14:in `block in process'
~/ruby/2.7.1/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/message/initialize.rb:10:in `process'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/host.rb:101:in `receive'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/adapter.rb:44:in `process'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/adapter.rb:17:in `block in opening'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/data_reader.rb:59:in `parse_message_from_buffer'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/data_reader.rb:35:in `block in receive'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/data_reader.rb:30:in `each_char'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/data_reader.rb:30:in `receive'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/solargraph-0.39.5/lib/solargraph/language_server/transport/adapter.rb:27:in `receiving'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/backport-1.1.2/lib/backport/client.rb:63:in `tick'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/backport-1.1.2/lib/backport/server/stdio.rb:18:in `update'
~/ruby/2.7.1/lib/ruby/2.7.0/observer.rb:197:in `block in notify_observers'
~/ruby/2.7.1/lib/ruby/2.7.0/observer.rb:196:in `each'
~/ruby/2.7.1/lib/ruby/2.7.0/observer.rb:196:in `notify_observers'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/backport-1.1.2/lib/backport/client.rb:121:in `read_input'
~/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/backport-1.1.2/lib/backport/client.rb:102:in `block in run_input_thread'
@castwide
Copy link
Owner

castwide commented May 3, 2020

I haven't been able to reproduce this one, but I have a hunch what caused it. The mapper seems to be reading past the end of a comment block with a YARD directive, probably starting with @! like @!method or @!attribute, and possibly because it's at the end of a file.

I'll try to fix what I suspect is the root cause, but if you can provide a reproducible example, it would help us be sure.

@aaronjensen
Copy link
Author

Any way I could get it to print the file it’s dying on?

@castwide
Copy link
Owner

castwide commented May 3, 2020

For now, the easiest way might be to create and run this script in your project's root:

# test-maps.rb
require 'solargraph'
workspace = Solargraph::Workspace.new('.')
workspace.filenames.each do |file|
  begin
    Solargraph::SourceMap.load(file)
  rescue StandardError => e
    puts "Error loading #{file}: #{e.message}"
  end
end

@aaronjensen
Copy link
Author

Thanks, that pinpointed it:

Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/atomic/atomic_reference.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/promises.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/executor_service.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_single_thread_executor.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb: undefined method `find_index' for nil:NilClass
Error loading ./gems/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/single_thread_executor.rb: undefined method `find_index' for nil:NilClass

@castwide
Copy link
Owner

castwide commented May 3, 2020

Perfect, thanks. The root cause is complicated @!macro directives. This is the minimal reproducible example I could make:

module Foo
  # @!macro macro1
  #   @!macro macro2
  #   @!method macro_method

  # @!macro macro1
  class Bar; end
end

Proper @!macro support is still a work in progress. For now, I can at least ensure that the mapper gracefully handles macros it doesn't understand.

One other note. Based on your file paths, it looks like you're mapping third-party gems in your workspace. If those gems are visible to Solargraph at runtime (e.g., installed on your system), you should be able to get intellisense for them without including them. Using cached gem documentation instead of mapping them should be significantly faster.

You can exclude them from the map by adding the gems directory to the exclude section of .solargraph.yml:

exclude:
- "gems"

A few other notes about include and exclude: https://solargraph.org/guides/performance

If there's some reason including gem code is more convenient for you, that should be fine, too. I just thought I'd mention an alternative.

@aaronjensen
Copy link
Author

Thank you for the quick response to this, I appreciate it.

The gems directory is where they're actually installed (using bundle --path=./gems) Does what you're describing still apply? I'm thinking I'd have to install the gems I was interested in globally as well, yes?

Also, I saw in #322 the mention of solargraph bundle. What does that do when I have gems installed in a local directory instead of my gem home? It looks like it may install those gems globally, is that right?

@castwide
Copy link
Owner

castwide commented May 3, 2020

Nonstandard gem paths can get tricky. One option is to use Solargraph with Bundler.

  1. Add Solargraph to your gemfile (e.g., gem 'solargraph', group: :development)
  2. Run solargraph bundle to make sure your gems have documentation. (Depending on your setup, it might need to be bundle exec solargraph bundle)
  3. Set up your editor to start Solargraph with Bundler. In VS Code, you can do this by setting solargraph.useBundler to true.

Running solargraph bundle will not install any gems. It just generates documentation for the gems it finds in your project's dependencies.

@castwide
Copy link
Owner

castwide commented May 3, 2020

The @!macro bug fix is released in v0.39.6. (There's also a fix for an unrelated bug that might affect projects with custom gem paths.)

@aaronjensen
Copy link
Author

That's great, thank you. So far so good.

@castwide castwide closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants