mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-27 20:29:39 +02:00
Refactor project and index handling
- Standardized formatting across key functions in `project.rs`. - Updated `index::handle` and `build_index` to incorporate the `config` parameter. - Improved index-building logic to include project details and enhanced issue tracking. - Replaced variable names like `files` with `paths` for clarity in `scan.rs`.
This commit is contained in:
parent
0eecf886f2
commit
ead64c0bd3
4 changed files with 66 additions and 36 deletions
|
|
@ -1,10 +1,15 @@
|
|||
use std::fs;
|
||||
use crate::cli::IndexAction;
|
||||
use crate::database::index::{Indexer, IssueRow};
|
||||
use crate::patterns::Severity;
|
||||
use crate::utils::Config;
|
||||
use crate::utils::project::get_project_info;
|
||||
use crate::walk::spawn_senders;
|
||||
|
||||
pub fn handle(
|
||||
action: IndexAction,
|
||||
database_dir: &std::path::Path,
|
||||
config: &Config,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match action {
|
||||
IndexAction::Build { path, force } => {
|
||||
|
|
@ -12,8 +17,7 @@ pub fn handle(
|
|||
let (project_name, db_path) = get_project_info(&build_path, database_dir)?;
|
||||
|
||||
if force || !db_path.exists() {
|
||||
println!("Building index for: {}", project_name);
|
||||
build_index(&build_path, &db_path)?;
|
||||
build_index(&project_name, &build_path, &db_path, config)?;
|
||||
println!("Index built: {}", db_path.display());
|
||||
} else {
|
||||
println!("Index already exists. Use --force to rebuild.");
|
||||
|
|
@ -38,10 +42,35 @@ pub fn handle(
|
|||
}
|
||||
|
||||
pub fn build_index(
|
||||
_project_path: &std::path::Path,
|
||||
project_name: &str,
|
||||
project_path: &std::path::Path,
|
||||
db_path: &std::path::Path,
|
||||
config: &Config,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// TODO: Implement actual index building
|
||||
tracing::debug!("Building index for: {}", project_name);
|
||||
fs::File::create(db_path)?;
|
||||
|
||||
let mut indexer = Indexer::new(&project_name, &db_path)?;
|
||||
let rx = spawn_senders(project_path, config);
|
||||
for path in rx.iter().flatten() {
|
||||
let issues = crate::commands::scan::run_rules_on_file(&path, config)?;
|
||||
let file_id = indexer.upsert_file(&path)?;
|
||||
|
||||
let issue_rows: Vec<IssueRow> = issues
|
||||
.iter()
|
||||
.map(|d| IssueRow {
|
||||
rule_id: d.id.as_ref(),
|
||||
severity: match d.severity {
|
||||
Severity::High => "HIGH",
|
||||
Severity::Medium => "MEDIUM",
|
||||
Severity::Low => "LOW",
|
||||
},
|
||||
line: d.line as i64,
|
||||
col: d.col as i64,
|
||||
})
|
||||
.collect();
|
||||
|
||||
indexer.replace_issues(file_id, issue_rows)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue