castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
425 stars 24 forks source link

uninitialized constant Gem::MissingSpecError #27

Closed mefellows closed 6 years ago

mefellows commented 6 years ago

Issue

When attempting code completing (command + tab) I experience a combination of:

The main error I often see is uninitialized constant Gem::MissingSpecError followed by a stack trace that references this file: gems/solargraph-0.17.2/lib/solargraph/yard_map.rb (see attached stack trace in solargraph-0.17.2.log).

The rescue on line 336 does not seem to capture this, as I believe that constant is only available in 2.4.0:

331     def process_requires
332       required.each do |r|
333         spec = Gem::Specification.find_by_path(r)
334         begin
335           spec = Gem::Specification.find_by_name(r) if spec.nil?
336         rescue Gem::MissingSpecError => e
337           # @todo How to handle this?
338         end
339         if spec.nil?
340           STDERR.puts "Required path not found (pgp): #{r}"
341         else
342           @gem_paths[spec.name] = spec.full_gem_path
343           add_gem_dependencies spec
344           result = YARD::Registry.yardoc_file_for_gem(spec.name)
345           yardocs.unshift result unless result.nil? or yardocs.include?(result)
346         end
347       end
348     end

Changing line 336 to just catch a general Exception gets us further (see the solargraph-patched log below), however it still suffers from terrible lag.

Setup Details

Ruby: 2.3.4 Solargraph: 0.17.2 Source code project: https://github.com/pact-foundation/pact_broker VS Code: Version 1.20.1 (1.20.1) f88bbf9137d24d36d968ea6b2911786bfe103002 VS Code Ruby: 0.16.0 VS Code Solargraph: 0.12.0

Files for debug

solargraph-0.17.2.log solargraph-0.17.2-patched.log

castwide commented 6 years ago

Thanks for the report. It looks like that block should rescue Gem::LoadError instead, which is compatible back to at least Ruby 2.2.2. I've pushed the change to the master branch.

I cloned the pact_broker repo for testing. I tried it on Windows 10 with Ruby 2.3.3 first. When I ran bundle install, it gave me the following error while installing database_cleaner:

Errno::EACCES: Permission denied @ rb_file_s_symlink - (examples/../Gemfile,
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/database_cleaner-1.6.2/examples/Gemfile)
An error occurred while installing database_cleaner (1.6.2), and Bundler cannot
continue.

I tried again on CentOS with Ruby 2.3.4, and bundle install gave me a different error:

Bundler could not find compatible versions for gem "ruby":
  In Gemfile:
    ruby

    pact_broker was resolved to 2.14.0, which depends on
      ruby (>= 2.2.0)

Could not find gem 'ruby (>= 2.2.0)', which is required by gem 'pact_broker',
in any of the relevant sources:
  the local ruby installation

Those errors might not be directly related to the performance problems you experienced, but they prevent me from testing the project in VS Code.

mefellows commented 6 years ago

Thanks for taking a look @castwide. That's weird, the build is passing at https://travis-ci.org/pact-foundation/pact_broker.

Interestingly it seems to be relatively performant on my Mac at home. I'll need to compare the setups to see if anything different.

castwide commented 6 years ago

I got bundle install to work on CentOS by updating bundler. (Strange, I thought I had already done that). I'll test it in VS Code and check for problems or bottlenecks.

mefellows commented 6 years ago

Oh good to hear, let me know if I can provide more detail or assistance. I'll provide an updated report when I can get to testing it at home too

castwide commented 6 years ago

Version 0.17.3 of the gem fixes the rescued exception in YardMap. I still plan to run some tests using pact_broker.

mefellows commented 6 years ago

Thanks for the quick fix!

mefellows commented 6 years ago

So in my attempt to get to the bottom of why my Mac at home worked, I clean installed VS Code and Solargraph just now, and now it too is super slow and suffers same issues as above. I can see the calls to /hover but the UI seems to always spin for ages.

Some files, seemingly randomly, are faster than others, but not to the point that you can just hover about to get definitions in any timely manner.

I wonder if it's related to the size of the code base? Is there anything I can help provide to make this report more useful or shall we close it off with some resolution?

castwide commented 6 years ago

I ran some tests with pact_broker on a MacBook and got the same sporadic performance you described. Part of the issue is definitely the size of the code base. You can try creating a .solargraph.yml file in your project root to avoid parsing files you don't need to map, such as unit tests and database migrations.

The solargraph config command creates a file with the default settings. Try changing the include section to the following:

include:
- "lib/**/*.rb"

That dropped the amount of code that gets parsed goes from 28Kloc to 11Kloc. You can add more entries if there are other files you want to map. There's more information about config files here: http://solargraph.org/tips

There are also some changes coming in the solargraph gem that should improve overall performance, such as improved detection of YARD documentation from required paths. You should see a slight boost in version 0.17.4, and a much bigger boost in a later update that implements Microsoft's language server protocol.

If you notice any specific circumstances where performance lags or anything like that, please feel free to report it. Most of these issues exist in the gem rather than the extension, so I might open related issues in the gem repo and link to them where applicable.

mefellows commented 6 years ago

Thanks @castwide, I'll give that a go and see if that helps. I'll close this for now, and look forward to future releases! :)