Skip to content

Commit 6952e37

Browse files
committed
refactor: split review file context sources
Made-with: Cursor
1 parent 2c16e6a commit 6952e37

File tree

6 files changed

+169
-140
lines changed

6 files changed

+169
-140
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
- [x] `src/review/pipeline/guidance.rs`: carve guidance assembly, repo-support guidance, and prompt-facing formatting.
104104
- [x] `src/review/pipeline/session.rs`: split session construction from runtime state transitions.
105105
- [x] `src/review/pipeline/services.rs`: separate service wiring from optional feature initialization.
106-
- [ ] `src/review/pipeline/file_context/sources.rs`: split repo sources, symbol sources, and supplemental context sources.
106+
- [x] `src/review/pipeline/file_context/sources.rs`: split repo sources, symbol sources, and supplemental context sources.
107107
- [ ] `src/review/pipeline/comments.rs`: separate comment assembly, filtering, and metadata stamping.
108108
- [ ] `src/review/pipeline/postprocess/dedup.rs`: split duplicate detection, scoring, and merge/rewrite behavior.
109109
- [ ] `src/review/pipeline/postprocess/feedback.rs`: separate store lookups from suppression/annotation decisions.
Lines changed: 13 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,13 @@
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;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::core;
2+
3+
use super::super::super::context::gather_related_file_context;
4+
use super::super::super::services::PipelineServices;
5+
use super::super::super::session::ReviewSession;
6+
7+
pub(in super::super) fn add_related_file_context(
8+
services: &PipelineServices,
9+
session: &ReviewSession,
10+
diff: &core::UnifiedDiff,
11+
context_chunks: &mut Vec<core::LLMContextChunk>,
12+
) {
13+
if let Some(index) = session.symbol_index.as_ref() {
14+
let caller_chunks =
15+
gather_related_file_context(index, &diff.file_path, &services.repo_path);
16+
context_chunks.extend(caller_chunks);
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use anyhow::Result;
2+
3+
use crate::core;
4+
5+
use super::super::super::services::PipelineServices;
6+
7+
pub(in super::super) async fn inject_repository_context(
8+
services: &PipelineServices,
9+
diff: &core::UnifiedDiff,
10+
context_chunks: &mut Vec<core::LLMContextChunk>,
11+
) -> Result<()> {
12+
super::super::super::super::context_helpers::inject_custom_context(
13+
&services.config,
14+
&services.context_fetcher,
15+
diff,
16+
context_chunks,
17+
)
18+
.await?;
19+
super::super::super::super::context_helpers::inject_pattern_repository_context(
20+
&services.config,
21+
&services.pattern_repositories,
22+
&services.context_fetcher,
23+
diff,
24+
context_chunks,
25+
)
26+
.await?;
27+
28+
Ok(())
29+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use anyhow::Result;
2+
3+
use crate::config;
4+
use crate::core;
5+
6+
use super::super::super::services::PipelineServices;
7+
use super::super::super::session::ReviewSession;
8+
9+
pub(in super::super) async fn add_semantic_context(
10+
services: &PipelineServices,
11+
session: &ReviewSession,
12+
diff: &core::UnifiedDiff,
13+
context_chunks: &mut Vec<core::LLMContextChunk>,
14+
) {
15+
let Some(index) = session.semantic_index.as_ref() else {
16+
return;
17+
};
18+
19+
let semantic_chunks = core::semantic_context_for_diff(
20+
index,
21+
diff,
22+
session
23+
.source_files
24+
.get(&diff.file_path)
25+
.map(|content| content.as_str()),
26+
services.embedding_adapter.as_deref(),
27+
services.config.semantic_rag_top_k,
28+
services.config.semantic_rag_min_similarity,
29+
)
30+
.await;
31+
context_chunks.extend(semantic_chunks);
32+
}
33+
34+
pub(in super::super) async fn add_path_context(
35+
services: &PipelineServices,
36+
diff: &core::UnifiedDiff,
37+
path_config: Option<&config::PathConfig>,
38+
context_chunks: &mut Vec<core::LLMContextChunk>,
39+
) -> Result<()> {
40+
let Some(path_config) = path_config else {
41+
return Ok(());
42+
};
43+
44+
if !path_config.focus.is_empty() {
45+
context_chunks.push(
46+
core::LLMContextChunk::documentation(
47+
diff.file_path.clone(),
48+
format!(
49+
"Focus areas for this file: {}",
50+
path_config.focus.join(", ")
51+
),
52+
)
53+
.with_provenance(core::ContextProvenance::PathSpecificFocusAreas),
54+
);
55+
}
56+
57+
if !path_config.extra_context.is_empty() {
58+
let extra_chunks = services
59+
.context_fetcher
60+
.fetch_additional_context(&path_config.extra_context)
61+
.await?;
62+
context_chunks.extend(extra_chunks);
63+
}
64+
65+
Ok(())
66+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use anyhow::Result;
2+
3+
use crate::core;
4+
5+
use super::super::super::context::extract_symbols_from_diff;
6+
use super::super::super::services::PipelineServices;
7+
use super::super::super::session::ReviewSession;
8+
9+
pub(in super::super) async fn add_symbol_context(
10+
services: &PipelineServices,
11+
session: &ReviewSession,
12+
diff: &core::UnifiedDiff,
13+
context_chunks: &mut Vec<core::LLMContextChunk>,
14+
) -> Result<()> {
15+
let symbols = extract_symbols_from_diff(diff);
16+
if symbols.is_empty() {
17+
return Ok(());
18+
}
19+
20+
let definition_chunks = services
21+
.context_fetcher
22+
.fetch_related_definitions(&diff.file_path, &symbols)
23+
.await?;
24+
context_chunks.extend(definition_chunks);
25+
26+
if let Some(index) = session.symbol_index.as_ref() {
27+
let index_chunks = services
28+
.context_fetcher
29+
.fetch_related_definitions_with_index(
30+
&diff.file_path,
31+
&symbols,
32+
index,
33+
services.config.symbol_index_max_locations,
34+
services.config.symbol_index_graph_hops,
35+
services.config.symbol_index_graph_max_files,
36+
)
37+
.await?;
38+
context_chunks.extend(index_chunks);
39+
}
40+
41+
Ok(())
42+
}

0 commit comments

Comments
 (0)