Class: SimpleCov::Formatter::AIFormatter::ASTResolver
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::AIFormatter::ASTResolver
- Extended by:
- T::Sig
- Defined in:
- lib/simplecov-ai/ast_resolver.rb
Overview
Employs statically-parsed Abstract Syntax Tree processing via the ‘parser` gem to correlate raw line-based deficits with high-level semantically meaningful concepts like Classes and Methods. This negates the line-number volatility often experienced by Large Language Models when patching test coverage.
Defined Under Namespace
Classes: SemanticNode
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.resolve(file_path) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simplecov-ai/ast_resolver.rb', line 59 def self.resolve(file_path) return [] unless File.exist?(file_path) source = File.read(file_path) ast, comments = Parser::CurrentRuby.parse_with_comments(source) resolver = new nodes = resolver.traverse(ast) resolver.assign_bypasses(nodes, comments) nodes end |
Instance Method Details
#assign_bypasses(nodes, comments) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/simplecov-ai/ast_resolver.rb', line 96 def assign_bypasses(nodes, comments) comments.each do |c| c_text = T.cast(c.text, String) next unless c_text.include?(':nocov:') assign_bypass(nodes, c, c_text.strip) end end |
#traverse(node, context = '') ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/simplecov-ai/ast_resolver.rb', line 81 def traverse(node, context = '') return [] unless node.is_a?(Parser::AST::Node) nodes = T.let([], T::Array[SemanticNode]) current_context, semantic_node = (node, context) nodes << semantic_node if semantic_node node.children.grep(Parser::AST::Node).each do |child| nodes.concat(traverse(child, current_context)) end nodes end |