lib/steep/services/signature_help_provider.rb in steep-1.6.0 vs lib/steep/services/signature_help_provider.rb in steep-1.7.0.dev.1
- old
+ new
@@ -53,11 +53,11 @@
if begin_loc && end_loc
if begin_loc.end_pos <= pos && pos <= end_loc.begin_pos
# Given position is between open/close parens of args of send node
- if parent && (parent.type == :block || parent.type == :numblock)
+ if parent && (parent.type == :block || parent.type == :numblock) && node.equal?(parent.children[0])
send_node = parent
else
send_node = node
end
@@ -74,11 +74,12 @@
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver)
end
def last_argument_nodes_for(argument_nodes:, line:, column:)
- return unless argument_nodes.last.children[2] # No arguments
+ last = argument_nodes.last or raise
+ return unless last.children[2] # No arguments
return argument_nodes if argument_nodes.size > 1 # Cursor is on the last argument
pos = buffer.loc_to_pos([line, column])
while true
@@ -148,22 +149,22 @@
method_type.type.required_positionals.size + method_type.type.optional_positionals.size + 1 if method_type.type.rest_positionals
when :kwargs
case last_argument_nodes[-3].type
when :pair
argname = last_argument_nodes[-3].children.first.children.first
- if method_type.type.required_keywords[argname]
+ if method_type.type.required_keywords.key?(argname)
positionals + method_type.type.required_keywords.keys.index(argname).to_i + 1
- elsif method_type.type.optional_keywords[argname]
+ elsif method_type.type.optional_keywords.key?(argname)
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.keys.index(argname).to_i + 1
elsif method_type.type.rest_keywords
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.size
end
when :kwsplat
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.size if method_type.type.rest_keywords
end
else
- pos = node.children[2...].index { |c| c.location == last_argument_nodes[-2].location }.to_i
+ pos = (node.children[2...] || raise).index { |c| c.location == last_argument_nodes[-2].location }.to_i
if method_type.type.rest_positionals
[pos + 1, positionals - 1].min
else
[pos + 1, positionals].min
end
@@ -175,21 +176,21 @@
method_type.type.required_positionals.size + method_type.type.optional_positionals.size if method_type.type.rest_positionals
when :kwargs
case argument_nodes[-3].type
when :pair
argname = argument_nodes[-3].children.first.children.first
- if method_type.type.required_keywords[argname]
+ if method_type.type.required_keywords.key?(argname)
positionals + method_type.type.required_keywords.keys.index(argname).to_i
- elsif method_type.type.optional_keywords[argname]
+ elsif method_type.type.optional_keywords.key?(argname)
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.keys.index(argname).to_i
elsif method_type.type.rest_keywords
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.size
end
when :kwsplat
positionals + method_type.type.required_keywords.size + method_type.type.optional_keywords.size if method_type.type.rest_keywords
end
else
- pos = node.children[2...].index { |c| c.location == argument_nodes[-2].location }.to_i
+ pos = (node.children[2...] || raise).index { |c| c.location == argument_nodes[-2].location }.to_i
[pos, positionals - 1].min
end
end
end
end