1use std::collections::HashSet;
4use std::path::PathBuf;
5
6pub use crate::cache::map_cache::RefreshMode;
7
8#[derive(Debug, Clone)]
10pub struct RepoMapConfig {
11 pub map_tokens: usize,
13 pub root: PathBuf,
15 pub repo_content_prefix: Option<String>,
17 pub verbose: bool,
19 pub max_context_window: Option<usize>,
21 pub map_mul_no_files: usize,
23 pub refresh: RefreshMode,
25 pub force_refresh: bool,
27 pub exclude_unranked: bool,
29 pub self_edge_weight: f64,
31 pub max_line_length: usize,
33 pub pagerank_damping: f64,
35 pub pagerank_tol: f64,
37 pub pagerank_max_iter: usize,
39 pub anchor_fnames: Vec<PathBuf>,
41 pub anchor_idents: HashSet<String>,
43 pub anchor_scoped: Vec<(PathBuf, String)>,
46 pub anchor_weight_multiplier: f64,
48}
49
50impl Default for RepoMapConfig {
51 fn default() -> Self {
52 Self {
53 map_tokens: 1024,
54 root: std::env::current_dir().unwrap_or_default(),
55 repo_content_prefix: None,
56 verbose: false,
57 max_context_window: None,
58 map_mul_no_files: 8,
59 refresh: RefreshMode::Auto,
60 force_refresh: false,
61 exclude_unranked: false,
62 self_edge_weight: 0.1,
63 max_line_length: 100,
64 pagerank_damping: 0.85,
65 pagerank_tol: 1e-6,
66 pagerank_max_iter: 100,
67 anchor_fnames: Vec::new(),
68 anchor_idents: HashSet::new(),
69 anchor_scoped: Vec::new(),
70 anchor_weight_multiplier: 10.0,
71 }
72 }
73}
74
75#[derive(Debug, Default)]
77pub struct RepoMapConfigBuilder {
78 config: RepoMapConfig,
79}
80
81impl RepoMapConfig {
82 pub fn builder() -> RepoMapConfigBuilder {
84 RepoMapConfigBuilder::default()
85 }
86}
87
88impl RepoMapConfigBuilder {
89 pub fn map_tokens(mut self, n: usize) -> Self {
91 self.config.map_tokens = n;
92 self
93 }
94
95 pub fn root(mut self, path: impl Into<PathBuf>) -> Self {
97 self.config.root = path.into();
98 self
99 }
100
101 pub fn repo_content_prefix(mut self, prefix: impl Into<String>) -> Self {
103 self.config.repo_content_prefix = Some(prefix.into());
104 self
105 }
106
107 pub fn verbose(mut self, v: bool) -> Self {
109 self.config.verbose = v;
110 self
111 }
112
113 pub fn max_context_window(mut self, n: Option<usize>) -> Self {
118 self.config.max_context_window = n;
119 self
120 }
121
122 pub fn map_mul_no_files(mut self, n: usize) -> Self {
124 self.config.map_mul_no_files = n;
125 self
126 }
127
128 pub fn refresh(mut self, mode: RefreshMode) -> Self {
130 self.config.refresh = mode;
131 self
132 }
133
134 pub fn force_refresh(mut self, v: bool) -> Self {
136 self.config.force_refresh = v;
137 self
138 }
139
140 pub fn exclude_unranked(mut self, v: bool) -> Self {
142 self.config.exclude_unranked = v;
143 self
144 }
145
146 pub fn self_edge_weight(mut self, w: f64) -> Self {
148 self.config.self_edge_weight = w;
149 self
150 }
151
152 pub fn max_line_length(mut self, n: usize) -> Self {
154 self.config.max_line_length = n;
155 self
156 }
157
158 pub fn pagerank_damping(mut self, d: f64) -> Self {
160 self.config.pagerank_damping = d;
161 self
162 }
163
164 pub fn pagerank_tol(mut self, t: f64) -> Self {
166 self.config.pagerank_tol = t;
167 self
168 }
169
170 pub fn pagerank_max_iter(mut self, n: usize) -> Self {
172 self.config.pagerank_max_iter = n;
173 self
174 }
175
176 pub fn anchor_fnames(mut self, fnames: Vec<std::path::PathBuf>) -> Self {
178 self.config.anchor_fnames = fnames;
179 self
180 }
181
182 pub fn anchor_idents(mut self, idents: std::collections::HashSet<String>) -> Self {
184 self.config.anchor_idents = idents;
185 self
186 }
187
188 pub fn anchor_scoped(mut self, scoped: Vec<(std::path::PathBuf, String)>) -> Self {
190 self.config.anchor_scoped = scoped;
191 self
192 }
193
194 pub fn anchor_weight_multiplier(mut self, m: f64) -> Self {
196 self.config.anchor_weight_multiplier = m;
197 self
198 }
199
200 pub fn build(self) -> crate::repo_map::RepoMap {
202 crate::repo_map::RepoMap::new(self.config)
203 }
204}