Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better const go to def jump #164

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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
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)