Skip to content

Commit d864510

Browse files
committed
Apply plugins to manual and smart reviews
1 parent b439e69 commit d864510

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

src/main.rs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ async fn review_command(
182182
format: OutputFormat,
183183
) -> Result<()> {
184184
info!("Starting diff review with model: {}", config.model);
185+
186+
let repo_root = core::GitIntegration::new(".")
187+
.ok()
188+
.and_then(|git| git.workdir())
189+
.unwrap_or_else(|| PathBuf::from("."));
190+
let repo_path_str = repo_root.to_string_lossy().to_string();
191+
let context_fetcher = core::ContextFetcher::new(repo_root.clone());
192+
193+
let mut plugin_manager = plugins::plugin::PluginManager::new();
194+
plugin_manager.load_builtin_plugins(&config.plugins).await?;
185195

186196
let diff_content = if let Some(path) = diff_path {
187197
tokio::fs::read_to_string(path).await?
@@ -214,13 +224,23 @@ async fn review_command(
214224
continue;
215225
}
216226

217-
let context_fetcher = core::ContextFetcher::new(PathBuf::from("."));
218227
let mut context_chunks = context_fetcher.fetch_context_for_file(
219228
&diff.file_path,
220229
&diff.hunks.iter()
221230
.map(|h| (h.new_start, h.new_start + h.new_lines))
222231
.collect::<Vec<_>>()
223232
).await?;
233+
234+
// Run pre-analyzers to get additional context
235+
let analyzer_chunks = plugin_manager.run_pre_analyzers(&diff, &repo_path_str).await?;
236+
context_chunks.extend(analyzer_chunks);
237+
238+
// Extract symbols from diff and fetch their definitions
239+
let symbols = extract_symbols_from_diff(&diff);
240+
if !symbols.is_empty() {
241+
let definition_chunks = context_fetcher.fetch_related_definitions(&diff.file_path, &symbols).await?;
242+
context_chunks.extend(definition_chunks);
243+
}
224244

225245
// Get path-specific configuration
226246
let path_config = config.get_path_config(&diff.file_path);
@@ -288,8 +308,12 @@ async fn review_command(
288308
}
289309
}
290310

311+
let processed_comments = plugin_manager
312+
.run_post_processors(all_comments, &repo_path_str)
313+
.await?;
314+
291315
let effective_format = if patch { OutputFormat::Patch } else { format };
292-
output_comments(&all_comments, output_path, effective_format).await?;
316+
output_comments(&processed_comments, output_path, effective_format).await?;
293317

294318
Ok(())
295319
}
@@ -972,6 +996,16 @@ async fn smart_review_command(
972996
output_path: Option<PathBuf>,
973997
) -> Result<()> {
974998
info!("Starting smart review analysis with model: {}", config.model);
999+
1000+
let repo_root = core::GitIntegration::new(".")
1001+
.ok()
1002+
.and_then(|git| git.workdir())
1003+
.unwrap_or_else(|| PathBuf::from("."));
1004+
let repo_path_str = repo_root.to_string_lossy().to_string();
1005+
let context_fetcher = core::ContextFetcher::new(repo_root.clone());
1006+
1007+
let mut plugin_manager = plugins::plugin::PluginManager::new();
1008+
plugin_manager.load_builtin_plugins(&config.plugins).await?;
9751009

9761010
let diff_content = if let Some(path) = diff_path {
9771011
tokio::fs::read_to_string(path).await?
@@ -1003,13 +1037,16 @@ async fn smart_review_command(
10031037
continue;
10041038
}
10051039

1006-
let context_fetcher = core::ContextFetcher::new(PathBuf::from("."));
10071040
let mut context_chunks = context_fetcher.fetch_context_for_file(
10081041
&diff.file_path,
10091042
&diff.hunks.iter()
10101043
.map(|h| (h.new_start, h.new_start + h.new_lines))
10111044
.collect::<Vec<_>>()
10121045
).await?;
1046+
1047+
// Run pre-analyzers to get additional context
1048+
let analyzer_chunks = plugin_manager.run_pre_analyzers(&diff, &repo_path_str).await?;
1049+
context_chunks.extend(analyzer_chunks);
10131050

10141051
// Get path-specific configuration
10151052
let path_config = config.get_path_config(&diff.file_path);
@@ -1073,9 +1110,14 @@ async fn smart_review_command(
10731110
}
10741111
}
10751112

1113+
// Run post-processors to filter and refine comments
1114+
let processed_comments = plugin_manager
1115+
.run_post_processors(all_comments, &repo_path_str)
1116+
.await?;
1117+
10761118
// Generate summary and output results
1077-
let summary = core::CommentSynthesizer::generate_summary(&all_comments);
1078-
let output = format_smart_review_output(&all_comments, &summary);
1119+
let summary = core::CommentSynthesizer::generate_summary(&processed_comments);
1120+
let output = format_smart_review_output(&processed_comments, &summary);
10791121

10801122
if let Some(path) = output_path {
10811123
tokio::fs::write(path, output).await?;

0 commit comments

Comments
 (0)