diff --git a/lib/typeprof/core/ast/const.rb b/lib/typeprof/core/ast/const.rb index 88241951d..2200cb398 100644 --- a/lib/typeprof/core/ast/const.rb +++ b/lib/typeprof/core/ast/const.rb @@ -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 diff --git a/lib/typeprof/core/ast/module.rb b/lib/typeprof/core/ast/module.rb index f848f1d9a..e171fac94 100644 --- a/lib/typeprof/core/ast/module.rb +++ b/lib/typeprof/core/ast/module.rb @@ -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: } diff --git a/lib/typeprof/core/service.rb b/lib/typeprof/core/service.rb index 340300420..17530da8b 100644 --- a/lib/typeprof/core/service.rb +++ b/lib/typeprof/core/service.rb @@ -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 diff --git a/scenario/service/definition.rb b/scenario/service/definition.rb index f3085cbc1..5eb4b6a96 100644 --- a/scenario/service/definition.rb +++ b/scenario/service/definition.rb @@ -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) @@ -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)