|
1 | | -use anyhow::Result; |
2 | | - |
3 | | -use crate::config; |
4 | | -use crate::core; |
5 | | - |
6 | | -use super::super::context::{extract_symbols_from_diff, gather_related_file_context}; |
7 | | -use super::super::services::PipelineServices; |
8 | | -use super::super::session::ReviewSession; |
9 | | - |
10 | | -pub(super) async fn add_symbol_context( |
11 | | - services: &PipelineServices, |
12 | | - session: &ReviewSession, |
13 | | - diff: &core::UnifiedDiff, |
14 | | - context_chunks: &mut Vec<core::LLMContextChunk>, |
15 | | -) -> Result<()> { |
16 | | - let symbols = extract_symbols_from_diff(diff); |
17 | | - if symbols.is_empty() { |
18 | | - return Ok(()); |
19 | | - } |
20 | | - |
21 | | - let definition_chunks = services |
22 | | - .context_fetcher |
23 | | - .fetch_related_definitions(&diff.file_path, &symbols) |
24 | | - .await?; |
25 | | - context_chunks.extend(definition_chunks); |
26 | | - |
27 | | - if let Some(index) = session.symbol_index.as_ref() { |
28 | | - let index_chunks = services |
29 | | - .context_fetcher |
30 | | - .fetch_related_definitions_with_index( |
31 | | - &diff.file_path, |
32 | | - &symbols, |
33 | | - index, |
34 | | - services.config.symbol_index_max_locations, |
35 | | - services.config.symbol_index_graph_hops, |
36 | | - services.config.symbol_index_graph_max_files, |
37 | | - ) |
38 | | - .await?; |
39 | | - context_chunks.extend(index_chunks); |
40 | | - } |
41 | | - |
42 | | - Ok(()) |
43 | | -} |
44 | | - |
45 | | -pub(super) fn add_related_file_context( |
46 | | - services: &PipelineServices, |
47 | | - session: &ReviewSession, |
48 | | - diff: &core::UnifiedDiff, |
49 | | - context_chunks: &mut Vec<core::LLMContextChunk>, |
50 | | -) { |
51 | | - if let Some(index) = session.symbol_index.as_ref() { |
52 | | - let caller_chunks = |
53 | | - gather_related_file_context(index, &diff.file_path, &services.repo_path); |
54 | | - context_chunks.extend(caller_chunks); |
55 | | - } |
56 | | -} |
57 | | - |
58 | | -pub(super) async fn add_semantic_context( |
59 | | - services: &PipelineServices, |
60 | | - session: &ReviewSession, |
61 | | - diff: &core::UnifiedDiff, |
62 | | - context_chunks: &mut Vec<core::LLMContextChunk>, |
63 | | -) { |
64 | | - let Some(index) = session.semantic_index.as_ref() else { |
65 | | - return; |
66 | | - }; |
67 | | - |
68 | | - let semantic_chunks = core::semantic_context_for_diff( |
69 | | - index, |
70 | | - diff, |
71 | | - session |
72 | | - .source_files |
73 | | - .get(&diff.file_path) |
74 | | - .map(|content| content.as_str()), |
75 | | - services.embedding_adapter.as_deref(), |
76 | | - services.config.semantic_rag_top_k, |
77 | | - services.config.semantic_rag_min_similarity, |
78 | | - ) |
79 | | - .await; |
80 | | - context_chunks.extend(semantic_chunks); |
81 | | -} |
82 | | - |
83 | | -pub(super) async fn add_path_context( |
84 | | - services: &PipelineServices, |
85 | | - diff: &core::UnifiedDiff, |
86 | | - path_config: Option<&config::PathConfig>, |
87 | | - context_chunks: &mut Vec<core::LLMContextChunk>, |
88 | | -) -> Result<()> { |
89 | | - let Some(path_config) = path_config else { |
90 | | - return Ok(()); |
91 | | - }; |
92 | | - |
93 | | - if !path_config.focus.is_empty() { |
94 | | - context_chunks.push( |
95 | | - core::LLMContextChunk::documentation( |
96 | | - diff.file_path.clone(), |
97 | | - format!( |
98 | | - "Focus areas for this file: {}", |
99 | | - path_config.focus.join(", ") |
100 | | - ), |
101 | | - ) |
102 | | - .with_provenance(core::ContextProvenance::PathSpecificFocusAreas), |
103 | | - ); |
104 | | - } |
105 | | - |
106 | | - if !path_config.extra_context.is_empty() { |
107 | | - let extra_chunks = services |
108 | | - .context_fetcher |
109 | | - .fetch_additional_context(&path_config.extra_context) |
110 | | - .await?; |
111 | | - context_chunks.extend(extra_chunks); |
112 | | - } |
113 | | - |
114 | | - Ok(()) |
115 | | -} |
116 | | - |
117 | | -pub(super) async fn inject_repository_context( |
118 | | - services: &PipelineServices, |
119 | | - diff: &core::UnifiedDiff, |
120 | | - context_chunks: &mut Vec<core::LLMContextChunk>, |
121 | | -) -> Result<()> { |
122 | | - super::super::super::context_helpers::inject_custom_context( |
123 | | - &services.config, |
124 | | - &services.context_fetcher, |
125 | | - diff, |
126 | | - context_chunks, |
127 | | - ) |
128 | | - .await?; |
129 | | - super::super::super::context_helpers::inject_pattern_repository_context( |
130 | | - &services.config, |
131 | | - &services.pattern_repositories, |
132 | | - &services.context_fetcher, |
133 | | - diff, |
134 | | - context_chunks, |
135 | | - ) |
136 | | - .await?; |
137 | | - |
138 | | - Ok(()) |
139 | | -} |
| 1 | +#[path = "sources/related.rs"] |
| 2 | +mod related; |
| 3 | +#[path = "sources/repo.rs"] |
| 4 | +mod repo; |
| 5 | +#[path = "sources/supplemental.rs"] |
| 6 | +mod supplemental; |
| 7 | +#[path = "sources/symbols.rs"] |
| 8 | +mod symbols; |
| 9 | + |
| 10 | +pub(super) use related::add_related_file_context; |
| 11 | +pub(super) use repo::inject_repository_context; |
| 12 | +pub(super) use supplemental::{add_path_context, add_semantic_context}; |
| 13 | +pub(super) use symbols::add_symbol_context; |
0 commit comments