Skip to content

Commit

Permalink
Better const go to def jump
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia authored and mame committed Apr 30, 2024
1 parent d372cdd commit e27b212
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/typeprof/core/ast/const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def initialize(raw_node, rhs, lenv)
# expr::C = expr
@cpath = AST.create_node(raw_node.target, lenv)
@static_cpath = AST.parse_cpath(raw_node.target, lenv.cref.cpath)
@cname_code_range = nil
@cname_code_range = TypeProf::CodeRange.from_node(raw_node.target)
when :constant_path_target_node
# expr::C, * = ary
@cpath = ConstantReadNode.new(raw_node, lenv)
@static_cpath = AST.parse_cpath(raw_node, lenv.cref.cpath)
@cname_code_range = nil
@cname_code_range = TypeProf::CodeRange.from_node(raw_node)
else
raise
end
Expand Down
4 changes: 3 additions & 1 deletion lib/typeprof/core/ast/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def initialize(raw_node, lenv, raw_cpath, raw_scope)
else
@body = nil
end

@cname_code_range = TypeProf::CodeRange.from_node(raw_node.constant_path)
end

attr_reader :tbl, :cpath, :static_cpath, :body
attr_reader :tbl, :cpath, :static_cpath, :cname_code_range, :body

def subnodes = { cpath:, body: }
def attrs = { static_cpath:, tbl: }
Expand Down
2 changes: 1 addition & 1 deletion lib/typeprof/core/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def definitions(path, pos)
when ConstReadSite
if site.const_read && site.const_read.cdef
site.const_read.cdef.defs.each do |cdef_node|
defs << [cdef_node.lenv.path, cdef_node.code_range]
defs << [cdef_node.lenv.path, cdef_node.cname_code_range]
end
end
when CallSite
Expand Down
18 changes: 16 additions & 2 deletions scenario/service/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ def foo(n)
Foo.new(1).bar
Foo.new(1).baz
Foo::BAR
Foo::BBAR = 1
Foo::BBAR
Foo::CCAR, Foo::DDAR = [1, 2]
Foo::CCAR
Foo::DDAR

## definition: test.rb:14:1
test.rb:(1,0)-(12,3)
test.rb:(1,6)-(1,9)

## definition: test.rb:14:5
test.rb:(6,6)-(6,16)
Expand All @@ -33,4 +38,13 @@ def foo(n)
test.rb:(4,2)-(4,24)

## definition: test.rb:17:5
test.rb:(2,2)-(2,9)
test.rb:(2,2)-(2,5)

## definition: test.rb:19:5
test.rb:(18,0)-(18,9)

## definition: test.rb:21:5
test.rb:(20,0)-(20,9)

## definition: test.rb:22:5
test.rb:(20,11)-(20,20)

0 comments on commit e27b212

Please sign in to comment.