Skip to content

Commit

Permalink
Merge pull request #518 from soutaro/fix-goto
Browse files Browse the repository at this point in the history
Fix goto-definition from method call inside block
  • Loading branch information
soutaro authored Mar 20, 2022
2 parents 079b718 + b1338c4 commit 06e8b99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/steep/services/goto_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def query_at(path:, line:, column:)
typing, signature = type_check_path(target: target, path: relative_path, content: source.content, line: line, column: column)
if typing
node, *parents = typing.source.find_nodes(line: line, column: column)

if node
case node.type
when :const, :casgn
Expand All @@ -136,7 +137,10 @@ def query_at(path:, line:, column:)
end
when :send
if test_ast_location(node.location.selector, line: line, column: column)
node = parents[0] if parents[0]&.type == :block
if (parent = parents[0]) && parent.type == :block && parent.children[0] == node
node = parents[0]
end

case call = typing.call_of(node: node)
when TypeInference::MethodCall::Typed, TypeInference::MethodCall::Error
call.method_decls.each do |decl|
Expand Down
18 changes: 18 additions & 0 deletions test/goto_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,24 @@ def test_method_block
end
end

def test_method_block_inner
type_check = type_check_service do |changes|
changes[Pathname("lib/test.rb")] = [ContentChange.string(<<RBS)]
[].each do |x|
nil.to_s
end
RBS
end

service = Services::GotoService.new(type_check: type_check, assignment: assignment)

service.definition(path: dir + "lib/test.rb", line: 2, column: 8).tap do |locs|
assert_any!(locs, size: 1) do |loc|
assert_equal Pathname("nil_class.rbs"), Pathname(loc.buffer.name).basename
end
end
end

def test_goto_definition_wrt_assignment
type_check = type_check_service do |changes|
changes[Pathname("sig/a.rbs")] = [ContentChange.string(<<RBS)]
Expand Down

0 comments on commit 06e8b99

Please sign in to comment.