Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder::BranchEnricher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/simplecov-ai/markdown_builder/branch_enricher.rb

Overview

Recovers the column offsets SimpleCov's Branch objects do not expose from the raw coverage data, so a missed branch can quote its exact inline expression. Descriptors are native Arrays in a live result and stringified ("[:then, 1, 7, 18, 7, 22]") once a result has been rebuilt from .resultset.json — SimpleCov's default, merged path — and are decoded with SimpleCov's own parser (see DECODER). Data SimpleCov itself cannot decode raises here exactly as it raises in SimpleCov, and the decode guard contains that to the file.

Constant Summary collapse

ColumnMap =

[start_col, end_col] byte offsets keyed by the SimpleCov branch they belong to (by identity; SimpleCov's Branch objects are never modified).

T.type_alias { T::Hash[SimpleCov::SourceFile::Branch, [Integer, Integer]] }
DESCRIPTOR_LENGTH =

Length of a [type, id, start_line, start_col, end_line, end_col] descriptor.

T.let(6, Integer)
Decoder =

A descriptor decoder: takes the file and one raw descriptor, returns the decoded value.

T.type_alias { T.proc.params(file: SimpleCov::SourceFile, descriptor: BasicObject).returns(Object) }
RUBY_DATA_PARSER_DECODER =

Decodes with the eval-free RubyDataParser of SimpleCov >= 1.0.

T.let(
  ->(_file, descriptor) { SimpleCov::SourceFile::RubyDataParser.call(descriptor) },
  Decoder
)
LEGACY_DECODER =

Decodes through the SourceFile's private restore_ruby_data_structure of SimpleCov < 1.0.

T.let(
  ->(file, descriptor) { T.cast(file.send(:restore_ruby_data_structure, descriptor), Object) },
  Decoder
)
DECODER =

The decoder of the installed SimpleCov, chosen once at load time. Both return a native Array as it is.

T.let(
  (defined?(SimpleCov::SourceFile::RubyDataParser) && RUBY_DATA_PARSER_DECODER) || LEGACY_DECODER, Decoder
)

Class Method Summary collapse

Class Method Details

.enrich(file) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/simplecov-ai/markdown_builder/branch_enricher.rb', line 47

def self.enrich(file)
  columns_by_key = index_columns_by_key(raw_descriptors(file))
  file.branches.each_with_object(empty_column_map) do |branch, column_map|
    columns = columns_by_key[branch_key(branch.type, branch.start_line, branch.end_line)]&.shift
    column_map[branch] = columns if columns
  end
end