Class: Moult::Flags::MethodIndex
- Inherits:
-
Object
- Object
- Moult::Flags::MethodIndex
- Defined in:
- lib/moult/flags.rb
Overview
Best-effort line -> enclosing-method resolution, reusing the Prism Parser so the minted ids are byte-identical to the hotspots/deadcode/duplication join keys. We attribute a call site to the innermost method whose span contains its line; files are parsed lazily and memoised. A reference outside any method (top-level code) resolves to nil. (Mirrors Duplication::MethodIndex.)
Instance Method Summary collapse
-
#initialize(root:, files:) ⇒ MethodIndex
constructor
A new instance of MethodIndex.
-
#symbol_id_at(rel_path, line) ⇒ String?
Symbol_id of the innermost containing method, or nil.
Constructor Details
#initialize(root:, files:) ⇒ MethodIndex
Returns a new instance of MethodIndex.
93 94 95 96 |
# File 'lib/moult/flags.rb', line 93 def initialize(root:, files:) @abs_by_rel = files.to_h { |abs| [SymbolId.relative_path(abs, root), abs] } @cache = {} end |
Instance Method Details
#symbol_id_at(rel_path, line) ⇒ String?
Returns symbol_id of the innermost containing method, or nil.
99 100 101 102 103 |
# File 'lib/moult/flags.rb', line 99 def symbol_id_at(rel_path, line) method = enclosing_method(rel_path, line) return nil unless method SymbolId.for(path: rel_path, start_line: method.span.start_line, fqname: method.name) end |