castwide / vscode-solargraph

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

Request completionItem/resolve failed #124

Closed asux closed 5 years ago

asux commented 5 years ago

I receiving this in output console many times when type:

[Error - 2:59:45 PM] Request completionItem/resolve failed.
  Message: [TypeError] no implicit conversion of nil into String
  Code: -32603 

VS Code: 1.35.1 (1.35.1) Solargraph: 0.32.5

gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.3.8 (2018-10-18 patchlevel 459) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Users/asux/.rvm/gems/ruby-2.3.8@enbro
  - USER INSTALLATION DIRECTORY: /Users/asux/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /Users/asux/.rvm/rubies/ruby-2.3.8/bin/ruby
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin
  - SPEC CACHE DIRECTORY: /Users/asux/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/asux/.rvm/rubies/ruby-2.3.8/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /Users/asux/.rvm/gems/ruby-2.3.8@enbro
     - /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/gems/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org/"]
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/asux/platform-tools
     - /Users/asux/bin
     - /Users/asux/scripts
     - /usr/local/Cellar/zplug/2.4.2/bin
     - /usr/local/opt/zplug/bin
     - /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin
     - /Users/asux/.rvm/gems/ruby-2.3.8@global/bin
     - /Users/asux/.rvm/rubies/ruby-2.3.8/bin
     - /Users/asux/.rvm/bin
     - /usr/local/opt/python/libexec/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/X11/bin
     - /Users/asux/platform-tools
     - /Users/asux/bin
     - /Users/asux/scripts
     - /Users/asux/.nvm/versions/node/v10.15.3/bin

From developer console:

[Extension Host] [WARN] Error processing request: [TypeError] no implicit conversion of nil into String
[WARN] ["/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/pin/attribute.rb:27:in `+'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/pin/attribute.rb:27:in `path'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `block in get_path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `select'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `get_path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map.rb:371:in `get_path_suggestions'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/library.rb:307:in `path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/host.rb:448:in `locate_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/message/completion_item/resolve.rb:9:in `process'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/host.rb:94:in `receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:36:in `process'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:14:in `block in opening'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:53:in `parse_message_from_buffer'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:31:in `block in receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:26:in `each_char'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:26:in `receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:25:in `receiving'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:63:in `tick'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/server/tcpip.rb:76:in `update'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:197:in `block in notify_observers'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:196:in `each'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:196:in `notify_observers'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:121:in `read_input'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:102:in `block in run_input_thread'"]
[WARN] Error processing request: [TypeError] no implicit conversion of nil into String
[WARN] ["/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/pin/attribute.rb:27:in `+'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/pin/attribute.rb:27:in `path'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `block in get_path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `select'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map/store.rb:58:in `get_path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/api_map.rb:371:in `get_path_suggestions'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/library.rb:307:in `path_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/host.rb:448:in `locate_pins'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/message/completion_item/resolve.rb:9:in `process'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/host.rb:94:in `receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:36:in `process'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:14:in `block in opening'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:53:in `parse_message_from_buffer'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:31:in `block in receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:26:in `each_char'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/data_reader.rb:26:in `receive'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.32.5/lib/solargraph/language_server/transport/adapter.rb:25:in `receiving'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:63:in `tick'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/server/tcpip.rb:76:in `update'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:197:in `block in notify_observers'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:196:in `each'", "/Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/observer.rb:196:in `notify_observers'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:121:in `read_input'", "/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/backport-1.1.1/lib/backport/client.rb:102:in `block in run_input_thread'"]
castwide commented 5 years ago

I suspect this issue is fixed in v0.33.0 (currently in the master branch), but if you can give me a simple reproducible example, I can investigate further. Based on the message, it looks the error happened during autocomplete, while collecting information about an attribute (e.g., a method declared with one of the attr_* methods).

asux commented 5 years ago

Seems you're right, when I start type flash or params, error occurs:

module Web::Controllers::Exports
  module InternalContracts
    class Create
      include Web::Action

      params do
        required(:internal_contract).schema do
          required(:start_date).filled(:str?)
          required(:end_date).filled(:str?)
          required(:state).maybe(:str?)
        end
      end

      def call(params)
        authorize! :contracts, :export

        if params.valid?
          schedule_mail
          flash[:info] = t('controllers.exports.contracts.mail_scheduled')
        else
          flash[:error] = params.errors
        end
        redirect_to routes.export_path
      end

      private

      def schedule_mail
        Mailers::Exports::Contract.schedule(
          user_id: current_user.id,
          export_type: :base,
          **params[:internal_contract]
        )
      end
    end
  end
end
castwide commented 5 years ago

Is that Hanami? I tried creating a Hanami project and adding that controller, just to see how Solargraph handled it. It definitely looks like the project's maps are incomplete, but I still couldn't reproduce the error.

asux commented 5 years ago

Yes, this is Hanami project. But it has many files.

castwide commented 5 years ago

Gem v0.33.0 is released. It should fix the problem with resolving attribute completion items.

asux commented 5 years ago

Seems works fine. Thank you @castwide!

asux commented 5 years ago

Wait, I restarted VS code and now see this:

[Error - 4:46:39 PM] Server initialization failed.
  Message: [TypeError] no implicit conversion of nil into String
  Code: -32603 
/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:3241 Error: [TypeError] no implicit conversion of nil into String
    at new ResponseError (/Users/asux/.vscode/extensions/castwide.solargraph-0.19.6/node_modules/vscode-languageclient/node_modules/vscode-jsonrpc/lib/messages.js:46)
    at handleResponse (/Users/asux/.vscode/extensions/castwide.solargraph-0.19.6/node_modules/vscode-languageclient/node_modules/vscode-jsonrpc/lib/main.js:430)
    at processMessageQueue (/Users/asux/.vscode/extensions/castwide.solargraph-0.19.6/node_modules/vscode-languageclient/node_modules/vscode-jsonrpc/lib/main.js:258)
    at Immediate.<anonymous> (/Users/asux/.vscode/extensions/castwide.solargraph-0.19.6/node_modules/vscode-languageclient/node_modules/vscode-jsonrpc/lib/main.js:242)
    at runCallback (/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/timers.js:696)
    at tryOnImmediate (/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/timers.js:667)
    at processImmediate (/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/timers.js:649)
castwide commented 5 years ago

Can you go to the workspace in a terminal and run solargraph scan -v? If something caused an exception, that might pinpoint where it happened. (The -v option will dump information about each map location it's scanning, which will be extremely verbose. The important part will be the last location and the result, which should either be a success message or an error.)

asux commented 5 years ago
% solargraph scan -v 
[INFO] Indexing workspace files in /Users/asux/Projects/enbro_crm
/Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/pin/attribute.rb:25:in `+': no implicit conversion of nil into String (TypeError)
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/pin/attribute.rb:25:in `path'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map/store.rb:226:in `block in index'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map/store.rb:203:in `each'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map/store.rb:203:in `index'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map/store.rb:12:in `initialize'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map.rb:109:in `new'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map.rb:109:in `catalog'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/api_map.rb:149:in `load'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/shell.rb:148:in `block in scan'
        from /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/lib/solargraph/shell.rb:147:in `scan'
        from /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
        from /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
        from /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
        from /Users/asux/.rvm/rubies/ruby-2.3.8/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/gems/solargraph-0.33.0/bin/solargraph:5:in `<top (required)>'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin/solargraph:23:in `load'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin/solargraph:23:in `<main>'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin/ruby_executable_hooks:24:in `eval'
        from /Users/asux/.rvm/gems/ruby-2.3.8@enbro/bin/ruby_executable_hooks:24:in `<main>'
castwide commented 5 years ago

Thanks. I suspect that happened because of an @!attribute directive without a name. I reproduced it like this:

class Example
  # @!attribute
end

Can you confirm whether your code contains an unnamed @!attribute? Either way, that shouldn't crash the server, so I'll fix it in a patch update.

asux commented 5 years ago

Yes, I found this:

# @!attribute [r]
# @return [String] the field name of the contract PDF template
attribute :field_name, Types::String
castwide commented 5 years ago

This syntax should work:

# @!attribute [r] field_name
#   @return [String] the field name of the contract PDF template
attribute :field_name, Types::String

Note that the @return tag is indented to attach it to the directive. More information: https://www.rubydoc.info/gems/yard/file/docs/Tags.md#attribute

I'll have the unnamed attribute bug fixed in a patch release tomorrow.

castwide commented 5 years ago

Gem v0.33.1 fixes the unnamed attribute bug.

asux commented 5 years ago

It no longer crashes, thanks!