Skip to content
Closed
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
102 changes: 2 additions & 100 deletions lib/solargraph/rbs_map/conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,6 @@ def fqns type_name
RBS_TO_CLASS.fetch(ns, ns)
end

# @param type_name [RBS::TypeName]
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
# @return [ComplexType::UniqueType]
def build_type type_name, type_args = []
# we use .absolute? below to tell the type object what to
# expect
rbs_name = type_name.relative!.to_s
base = RBS_TO_CLASS.fetch(rbs_name, rbs_name)

params = type_args.map { |a| RbsTranslator.to_complex_type(a) }
# @todo Tuples are in flux
# tuples have their own class and are handled in other_type_to_type
if base == 'Hash' && params.length == 2
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: type_name.absolute?,
parameters_type: :hash)
else
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: type_name.absolute?,
parameters_type: :list)
end
end

# @param decl [RBS::AST::Declarations::Module::Self]
# @param closure [Pin::Namespace]
# @return [void]
Expand Down Expand Up @@ -561,7 +540,8 @@ def method_def_to_pin decl, closure, context
def method_def_to_sigs decl, pin
# rubocop:disable Style/SafeNavigationChainLength
implicit_nil = decl.overloads.first&.annotations&.map(&:string)&.include?('implicitly-returns-nil') || false
# rubocop:enable Style/SafeNavigationChainLength # @param overload [RBS::AST::Members::MethodDefinition::Overload]
# rubocop:enable Style/SafeNavigationChainLength
# @param overload [RBS::AST::Members::MethodDefinition::Overload]
decl.overloads.map do |overload|
type_location = location_decl_to_pin_location(overload.method_type.location)
generics = overload.method_type.type_params.map(&:name).map(&:to_s)
Expand All @@ -587,84 +567,6 @@ def location_decl_to_pin_location(location)
Location.new(location.name.to_s, range)
end

# @param type [RBS::MethodType, RBS::Types::Block]
# @param pin [Pin::Method]
# @param implicit_nil [Boolean]
# @return [Array(Array<Pin::Parameter>, ComplexType)]
def parts_of_function type, pin, implicit_nil
type_location = pin.type_location
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
return [
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs,
type_location: type_location)],
method_type_to_type(type, implicit_nil)
]
end

parameters = []
arg_num = -1
type.type.required_positionals.each do |param|
# @sg-ignore Unresolved call to name
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin,
# @sg-ignore RBS generic type understanding issue
return_type: other_type_to_type(param.type),
source: :rbs, type_location: type_location)
end
type.type.optional_positionals.each do |param|
# @sg-ignore Unresolved call to name
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
# @sg-ignore RBS generic type understanding issue
return_type: other_type_to_type(param.type),
type_location: type_location,
source: :rbs)
end
if type.type.rest_positionals
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
inner_rest_positional_type = other_type_to_type(type.type.rest_positionals.type)
rest_positional_type = ComplexType::UniqueType.new('Array',
[],
[inner_rest_positional_type],
rooted: true, parameters_type: :list)
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin,
source: :rbs, type_location: type_location,
return_type: rest_positional_type)
end
type.type.trailing_positionals.each do |param|
# @sg-ignore Unresolved call to name
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs,
type_location: type_location)
end
type.type.required_keywords.each do |orig, param|
# @sg-ignore Unresolved call to to_s
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
# @sg-ignore RBS generic type understanding issue
return_type: other_type_to_type(param.type),
source: :rbs, type_location: type_location)
end
type.type.optional_keywords.each do |orig, param|
# @sg-ignore Unresolved call to to_s
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
# @sg-ignore RBS generic type understanding issue
return_type: other_type_to_type(param.type),
type_location: type_location,
source: :rbs)
end
if type.type.rest_keywords
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg,
name: type.type.rest_keywords.name.to_s, closure: pin,
source: :rbs, type_location: type_location)
end

return_type = method_type_to_type(type, implicit_nil)
[parameters, return_type]
end

# @param type [RBS::MethodType,RBS::Types::Block]
# @param pin [Pin::Method]
# @param implicit_nil [Boolean]
Expand Down
Loading