Skip to content

Commit

Permalink
YardPin::Method skips invalid parameters (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Jul 25, 2020
1 parent f6bff26 commit 68aef05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 16 additions & 1 deletion lib/solargraph/pin/yard_pin/method.rb
Expand Up @@ -6,6 +6,12 @@ module YardPin
class Method < Pin::Method
include YardMixin

# @param code_object [YARD::CodeObjects::Base]
# @param name [String, nil]
# @param scope [Symbol, nil]
# @param visibility [Symbol, nil]
# @param closure [Solargraph::Pin::Closure, nil]
# @param spec [Gem::Specification]
def initialize code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
closure ||= Solargraph::Pin::Namespace.new(
name: code_object.namespace.to_s,
Expand All @@ -25,9 +31,14 @@ def initialize code_object, name = nil, scope = nil, visibility = nil, closure =

private

# @param code_object [YARD::CodeObjects::Base]
# @return [Array<Solargraph::Pin::Parameter>]
def get_parameters code_object
return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
code_object.parameters.map do |a|
# HACK: Skip `nil` and `self` parameters that are sometimes emitted
# for methods defined in C
# See https://github.com/castwide/solargraph/issues/345
code_object.parameters.select { |a| a[0] && a[0] != 'self' }.map do |a|
Solargraph::Pin::Parameter.new(
location: location,
closure: self,
Expand All @@ -40,10 +51,14 @@ def get_parameters code_object
end
end

# @param a [Array]
# @return [String]
def arg_name a
a[0].match(/[A-Za-z0-9_]*/)[0]
end

# @param a [Array]
# @return [Symbol]
def arg_type a
if a[0].start_with?('**')
:kwrestarg
Expand Down
10 changes: 2 additions & 8 deletions lib/solargraph/pin/yard_pin/yard_mixin.rb
Expand Up @@ -4,16 +4,10 @@ module Solargraph
module Pin
module YardPin
module YardMixin
attr_reader :code_object

attr_reader :spec

attr_reader :location

@@gate_cache ||= {}

private

# @param code_object [YARD::CodeObjects::Base]
# @param spec [Gem::Specification]
# @return [Solargraph::Location, nil]
def object_location code_object, spec
return nil if spec.nil? || code_object.nil? || code_object.file.nil? || code_object.line.nil?
Expand Down

0 comments on commit 68aef05

Please sign in to comment.