lib/tapioca/runtime/trackers/constant_definition.rb in tapioca-0.10.1 vs lib/tapioca/runtime/trackers/constant_definition.rb in tapioca-0.10.2

- old
+ new

@@ -7,10 +7,11 @@ # Registers a TracePoint immediately upon load to track points at which # classes and modules are opened for definition. This is used to track # correspondence between classes/modules and files, as this information isn't # available in the ruby runtime without extra accounting. module ConstantDefinition + extend Tracker extend Reflection extend T::Sig class ConstantLocation < T::Struct const :lineno, Integer @@ -18,11 +19,11 @@ end @class_files = {}.compare_by_identity # Immediately activated upon load. Observes class/module definition. - Tapioca.register_trace(:class) do |tp| + @class_tracepoint = TracePoint.trace(:class) do |tp| next if tp.self.singleton_class? key = tp.self path = tp.path @@ -38,22 +39,29 @@ end (@class_files[key] ||= Set.new) << loc end - Tapioca.register_trace(:c_return) do |tp| + @creturn_tracepoint = TracePoint.trace(:c_return) do |tp| next unless tp.method_id == :new - next unless Module === tp.return_value key = tp.return_value + next unless Module === key + loc = build_constant_location(tp, caller_locations) (@class_files[key] ||= Set.new) << loc end class << self + def disable! + @class_tracepoint.disable + @creturn_tracepoint.disable + super + end + def build_constant_location(tp, locations) - file = resolve_loc(caller_locations) - lineno = file == File.realpath(tp.path) ? tp.lineno : 0 + file = resolve_loc(locations) + lineno = File.identical?(file, tp.path) ? tp.lineno : 0 ConstantLocation.new(path: file, lineno: lineno) end # Returns the files in which this class or module was opened. Doesn't know