|
| 1 | +//! This module defines the `Code2PromptConfig` struct and its Builder for configuring the behavior |
| 2 | +//! of code2prompt in a stateless manner. It includes all parameters needed for file traversal, |
| 3 | +//! code filtering, token counting, and more. |
| 4 | +
|
| 5 | +use crate::template::OutputFormat; |
| 6 | +use crate::tokenizer::TokenizerType; |
| 7 | +use crate::{sort::FileSortMethod, tokenizer::TokenFormat}; |
| 8 | +use derive_builder::Builder; |
| 9 | +use std::path::PathBuf; |
| 10 | + |
| 11 | +/// A stateless configuration object describing all the preferences and filters |
| 12 | +/// applied when generating a code prompt. It does not store any mutable data, |
| 13 | +/// so it can be cloned freely or shared across multiple sessions. |
| 14 | +#[derive(Debug, Clone, Default, Builder)] |
| 15 | +#[builder(setter(into), default)] |
| 16 | +pub struct Code2PromptConfig { |
| 17 | + /// Path to the root directory of the codebase. |
| 18 | + pub path: PathBuf, |
| 19 | + |
| 20 | + /// List of glob-like patterns to include. |
| 21 | + #[builder(default)] |
| 22 | + pub include_patterns: Vec<String>, |
| 23 | + |
| 24 | + /// List of glob-like patterns to exclude. |
| 25 | + #[builder(default)] |
| 26 | + pub exclude_patterns: Vec<String>, |
| 27 | + |
| 28 | + /// If true, include patterns have priority over exclude patterns in case of conflicts. |
| 29 | + #[builder(default)] |
| 30 | + pub include_priority: bool, |
| 31 | + |
| 32 | + /// If true, code lines will be numbered in the output. |
| 33 | + #[builder(default)] |
| 34 | + pub line_numbers: bool, |
| 35 | + |
| 36 | + /// If true, paths in the output will be relative instead of absolute. |
| 37 | + #[builder(default)] |
| 38 | + pub relative_paths: bool, |
| 39 | + |
| 40 | + /// If true, code2prompt will generate a full directory tree, ignoring include/exclude rules. |
| 41 | + #[builder(default)] |
| 42 | + pub full_directory_tree: bool, |
| 43 | + |
| 44 | + /// If true, code blocks will not be wrapped in Markdown fences (```). |
| 45 | + #[builder(default)] |
| 46 | + pub no_codeblock: bool, |
| 47 | + |
| 48 | + /// If true, symbolic links will be followed during traversal. |
| 49 | + #[builder(default)] |
| 50 | + pub follow_symlinks: bool, |
| 51 | + |
| 52 | + /// If true, hidden files and directories will be included. |
| 53 | + #[builder(default)] |
| 54 | + pub hidden: bool, |
| 55 | + |
| 56 | + /// If true, .gitignore rules will be ignored. |
| 57 | + #[builder(default)] |
| 58 | + pub no_ignore: bool, |
| 59 | + |
| 60 | + /// Defines the sorting method for files. |
| 61 | + #[builder(default)] |
| 62 | + pub sort_method: Option<FileSortMethod>, |
| 63 | + |
| 64 | + /// Determines the output format of the final prompt. |
| 65 | + #[builder(default)] |
| 66 | + pub output_format: OutputFormat, |
| 67 | + |
| 68 | + /// An optional custom Handlebars template string. |
| 69 | + #[builder(default)] |
| 70 | + pub custom_template: Option<String>, |
| 71 | + |
| 72 | + /// The tokenizer encoding to use for counting tokens. |
| 73 | + #[builder(default)] |
| 74 | + pub encoding: TokenizerType, |
| 75 | + |
| 76 | + /// The counting format to use for token counting. |
| 77 | + #[builder(default)] |
| 78 | + pub token_format: TokenFormat, |
| 79 | + |
| 80 | + /// If true, the git diff between HEAD and index will be included. |
| 81 | + #[builder(default)] |
| 82 | + pub diff_enabled: bool, |
| 83 | + |
| 84 | + /// If set, contains two branch names for which code2prompt will generate a git diff. |
| 85 | + #[builder(default)] |
| 86 | + pub diff_branches: Option<(String, String)>, |
| 87 | + |
| 88 | + /// If set, contains two branch names for which code2prompt will retrieve the git log. |
| 89 | + #[builder(default)] |
| 90 | + pub log_branches: Option<(String, String)>, |
| 91 | + |
| 92 | + /// The name of the template used. |
| 93 | + #[builder(default)] |
| 94 | + pub template_name: String, |
| 95 | + |
| 96 | + /// The template string itself. |
| 97 | + #[builder(default)] |
| 98 | + pub template_str: String, |
| 99 | +} |
| 100 | + |
| 101 | +impl Code2PromptConfig { |
| 102 | + pub fn builder() -> Code2PromptConfigBuilder { |
| 103 | + Code2PromptConfigBuilder::default() |
| 104 | + } |
| 105 | +} |
0 commit comments