Skip to content

refactor: Modularize ContextGenerator::generate for Better Maintainability #43

@BETAER-08

Description

@BETAER-08

Problem

The ContextGenerator::generate function in src/core/generator.rs is currently a massive, monolithic block of code. It handles multiple responsibilities: resolving focus targets, fallback vector searching, expanding the call graph, and formatting the Markdown string. This violates the Single Responsibility Principle and makes the core logic hard to maintain.

Proposed Solution

  • Extract specific responsibilities into smaller, private helper functions within ContextGenerator:
    • resolve_focus_targets(query) -> Vec<String>
    • expand_graph_depth(initial_targets, depth) -> Vec<String>
    • format_markdown_report(files, edges) -> String
  • Clean up the main generate function to act simply as an orchestrator.

Definition of Done

  • generate function is broken down into smaller, logical sub-functions.
  • Core functionality remains identical (no regression in Markdown output).
  • Code readability and maintainability are vastly improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreLogic for Indexer, Parser, Graph, or Generator.priority: mediumNormal priority; adds value but not urgent.refactorCode change that neither fixes a bug nor adds a feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions