Skip to content
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
17 changes: 16 additions & 1 deletion lib/typeprof/core/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ def completion(path, trigger, pos)
end
end

def format_declared_const_path(cpath, stack)
scope_cpath =
stack.reverse_each.find do |entry|
(entry.is_a?(AST::ClassNode) || entry.is_a?(AST::ModuleNode)) &&
entry.static_cpath &&
!entry.static_cpath.empty?
end&.static_cpath

return cpath.join("::") unless scope_cpath
return cpath.join("::") unless cpath[0, scope_cpath.size] == scope_cpath

rel_cpath = cpath.drop(scope_cpath.size)
rel_cpath.empty? ? cpath.join("::") : rel_cpath.join("::")
end

def dump_declarations(path)
stack = []
out = []
Expand Down Expand Up @@ -465,7 +480,7 @@ def dump_declarations(path)
when AST::ConstantWriteNode
if node.static_cpath
if event == :enter
out << " " * stack.size + "#{ node.static_cpath.join("::") }: #{ node.ret.show }"
out << " " * stack.size + "#{ format_declared_const_path(node.static_cpath, stack) }: #{ node.ret.show }"
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion scenario/const/basic1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def foo(_)

## assert
class C
C::X: Integer
X: Integer
end
class D < C
end
Expand Down
2 changes: 1 addition & 1 deletion scenario/const/basic2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def foo
## assert
C: Integer
class Foo
Foo::C: Float
C: Float
def foo: -> Integer
end
Foo::Bar: :bar
File renamed without changes.
2 changes: 1 addition & 1 deletion scenario/const/module_const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def check
## diagnostics
## assert
module M
M::C: :test
C: :test
end
class C
include M
Expand Down
2 changes: 1 addition & 1 deletion scenario/known-issues/multi-const-write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class C

## assert
class C
C::D: (Integer | String)
D: (Integer | String)
end
2 changes: 1 addition & 1 deletion scenario/variable/and_write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_attr=(x)
## diagnostics
## assert
class C
C::D: :ConstD
D: :ConstD
def get_lv: -> (:LVar | :LVar0)
def set_iv: -> (:IVar | :IVar0)
def get_iv: -> (:IVar | :IVar0)
Expand Down
4 changes: 2 additions & 2 deletions scenario/variable/operator_write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_attr=(x)
## diagnostics
## assert
class C
C::D: Integer
C::D: Integer
D: Integer
D: Integer
def get_lv: -> Integer
def set_iv: -> Integer
def get_iv: -> Integer
Expand Down
2 changes: 1 addition & 1 deletion scenario/variable/or_write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_attr=(x)
## diagnostics
## assert
class C
C::D: :ConstD
D: :ConstD
def get_lv: -> :LVar
def set_iv: -> :IVar
def get_iv: -> :IVar
Expand Down