Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/solargraph/api_map/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ def map_overrides
ovr.tags.each do |tag|
pin.docstring.add_tag(tag)
redefine_return_type pin, tag
if new_pin
new_pin.docstring.add_tag(tag)
redefine_return_type new_pin, tag
end
pin.reset_generated!

next unless new_pin

new_pin.docstring.add_tag(tag)
redefine_return_type new_pin, tag
new_pin.comments = new_pin.docstring.to_raw + "\n"
new_pin.reset_generated!
end
end
end
Expand All @@ -159,7 +163,6 @@ def redefine_return_type pin, tag
pin.signatures.each do |sig|
sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
end
pin.reset_generated!
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions lib/solargraph/pin/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@
# @param api_map [ApiMap]
# @return [self]
def realize api_map
return self if return_type.defined?
return self if return_type.defined? && return_type.all_rooted?
type = typify(api_map)
return proxy(type) if type.defined?
return proxy(type) if type.defined? && type.all_rooted?
type = probe(api_map)
return self if type.undefined?
result = proxy(type)
Expand All @@ -565,6 +565,7 @@
result = dup
result.return_type = return_type
result.proxied = true
result.reset_generated!
result
end

Expand Down Expand Up @@ -639,6 +640,8 @@

# @return [void]
def reset_generated!
@docstring = nil
@directives = nil
end

protected
Expand Down Expand Up @@ -671,6 +674,15 @@
@docstring = parse.to_docstring
@directives = parse.directives
end
if @return_type&.defined?

Check warning on line 677 in lib/solargraph/pin/base.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Use a guard clause (`return unless @return_type&.defined?`) instead of wrapping the code inside a conditional expression. Raw Output: lib/solargraph/pin/base.rb:677:9: C: Style/GuardClause: Use a guard clause (`return unless @return_type&.defined?`) instead of wrapping the code inside a conditional expression.
@docstring ||= Solargraph::Source.parse_docstring("\n").to_docstring
rooted_types = @return_type.items.map(&:rooted_tag)
if @docstring.tags(:return)&.length == 1
@docstring.tag(:return).types = rooted_types
else
@docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_types))
end
end
end

# True if two docstrings have the same tags, regardless of any other
Expand Down
4 changes: 3 additions & 1 deletion lib/solargraph/pin/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Pin
# The base class for method and attribute pins.
#
class Method < Callable

Check warning on line 7 in lib/solargraph/pin/method.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Class has too many lines. [501/500] Raw Output: lib/solargraph/pin/method.rb:7:5: C: Metrics/ClassLength: Class has too many lines. [501/500]
include Solargraph::Parser::NodeMethods

# @return [::Symbol] :public, :private, or :protected
Expand All @@ -12,6 +12,8 @@

attr_writer :signatures

attr_writer :comments

# @return [Parser::AST::Node]
attr_reader :node

Expand Down Expand Up @@ -127,7 +129,7 @@
block&.reset_generated!
@signatures&.each(&:reset_generated!)
signature_help = nil
documentation = nil
@documentation = nil
end

def all_rooted?
Expand Down
31 changes: 15 additions & 16 deletions lib/solargraph/rbs_map/conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,15 @@
name = parts.first
closure = Solargraph::Pin::ROOT_PIN
end
return_type = ComplexType.parse(tag).force_rooted
constant_pin = Solargraph::Pin::Constant.new(

Check warning on line 254 in lib/solargraph/rbs_map/conversions.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Redundant assignment before returning detected. Raw Output: lib/solargraph/rbs_map/conversions.rb:254:9: C: Style/RedundantAssignment: Redundant assignment before returning detected.
name: name,
closure: closure,
type_location: location_decl_to_pin_location(decl.location),
comments: comments,
return_type: return_type,
source: :rbs
)
tag = "#{base}<#{tag}>" if base
rooted_tag = ComplexType.parse(tag).force_rooted.rooted_tags
constant_pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
constant_pin
end

Expand Down Expand Up @@ -295,15 +294,15 @@
def global_decl_to_pin decl
closure = Solargraph::Pin::ROOT_PIN
name = decl.name.to_s
return_type = ComplexType.parse(other_type_to_tag(decl.type))
pin = Solargraph::Pin::GlobalVariable.new(
name: name,
closure: closure,
comments: decl.comment&.string,
type_location: location_decl_to_pin_location(decl.location),
return_type: return_type,
source: :rbs
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
pins.push pin
end

Expand Down Expand Up @@ -516,6 +515,7 @@
name = decl.name.to_s
final_scope = decl.kind == :instance ? :instance : :class
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
return_type = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted
pin = Solargraph::Pin::Method.new(
name: name,
type_location: location_decl_to_pin_location(decl.location),
Expand All @@ -524,10 +524,9 @@
scope: final_scope,
attribute: true,
visibility: visibility,
return_type: return_type,
source: :rbs
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
logger.debug { "Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}" }
pins.push pin
end
Expand All @@ -541,6 +540,7 @@
name = "#{decl.name.to_s}="
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
type_location = location_decl_to_pin_location(decl.location)
return_type = ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted
pin = Solargraph::Pin::Method.new(
name: name,
type_location: type_location,
Expand All @@ -550,18 +550,17 @@
scope: final_scope,
attribute: true,
visibility: visibility,
return_type: return_type,
source: :rbs
)
pin.parameters <<
Solargraph::Pin::Parameter.new(
name: 'value',
return_type: ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted,
return_type: return_type,
source: :rbs,
closure: pin,
type_location: type_location
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
pins.push pin
end

Expand All @@ -578,15 +577,15 @@
# @param closure [Pin::Namespace]
# @return [void]
def ivar_to_pin(decl, closure)
return_type = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted
pin = Solargraph::Pin::InstanceVariable.new(
name: decl.name.to_s,
closure: closure,
type_location: location_decl_to_pin_location(decl.location),
comments: decl.comment&.string,
return_type: return_type,
source: :rbs
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
pins.push pin
end

Expand All @@ -595,15 +594,15 @@
# @return [void]
def cvar_to_pin(decl, closure)
name = decl.name.to_s
return_type = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted
pin = Solargraph::Pin::ClassVariable.new(
name: name,
closure: closure,
comments: decl.comment&.string,
type_location: location_decl_to_pin_location(decl.location),
return_type: return_type,
source: :rbs
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
pins.push pin
end

Expand All @@ -612,15 +611,15 @@
# @return [void]
def civar_to_pin(decl, closure)
name = decl.name.to_s
return_type = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted
pin = Solargraph::Pin::InstanceVariable.new(
name: name,
closure: closure,
comments: decl.comment&.string,
type_location: location_decl_to_pin_location(decl.location),
return_type: return_type,
source: :rbs
)
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
pins.push pin
end

Expand Down
Loading