MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / build_context

Function build_context

benches/queries.rs:100–147  ·  view source on GitHub ↗
(cg: &TraceDecay)

Source from the content-addressed store, hash-verified

98}
99
100pub async fn build_context(cg: &TraceDecay) -> QueryContext {
101 let all = cg.get_all_nodes().await.unwrap_or_default();
102
103 let mut function_ids = Vec::new();
104 let mut struct_ids = Vec::new();
105 let mut function_qnames = Vec::new();
106 let mut any_ids = Vec::new();
107
108 for n in &all {
109 any_ids.push(n.id.clone());
110 match n.kind {
111 NodeKind::Function | NodeKind::Method => {
112 function_ids.push(n.id.clone());
113 if !n.qualified_name.is_empty() && function_qnames.len() < 64 {
114 function_qnames.push(n.qualified_name.clone());
115 }
116 }
117 NodeKind::Struct | NodeKind::Class => {
118 struct_ids.push(n.id.clone());
119 }
120 _ => {}
121 }
122 }
123
124 function_ids.truncate(64);
125 struct_ids.truncate(64);
126 any_ids.truncate(64);
127
128 let files = cg.get_all_files().await.unwrap_or_default();
129
130 // Collect first-segment directory prefixes from the sample files (so
131 // `path_prefix` queries are valid for *this* repo regardless of layout).
132 let mut dir_prefixes: Vec<String> = files
133 .iter()
134 .filter_map(|f| f.path.split('/').next().map(str::to_string))
135 .collect();
136 dir_prefixes.sort();
137 dir_prefixes.dedup();
138 dir_prefixes.truncate(5);
139
140 QueryContext {
141 function_ids,
142 struct_ids,
143 any_ids,
144 function_qnames,
145 dir_prefixes,
146 }
147}
148
149fn five<F: FnMut(usize) -> Query>(mut f: F) -> Vec<Query> {
150 (0..5).map(&mut f).collect()

Callers 1

prepare_repoFunction · 0.85

Calls 5

pushMethod · 0.80
collectMethod · 0.80
get_all_nodesMethod · 0.45
is_emptyMethod · 0.45
get_all_filesMethod · 0.45

Tested by

no test coverage detected