Skip to content

Commit 79cfac1

Browse files
author
betaer
committed
style: apply rustfmt for v0.7.0 release
1 parent 8f511c4 commit 79cfac1

9 files changed

Lines changed: 208 additions & 74 deletions

File tree

src/core/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ impl Default for Config {
5353
ignore_patterns: default_ignore_patterns(),
5454
}
5555
}
56-
}
56+
}

src/core/generator.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use crate::core::embedding::EmbeddingEngine;
2+
use crate::core::graph::DependencyGraph;
3+
use crate::core::symbol::SymbolRef;
4+
use crate::core::vector_store::VectorStore;
5+
use crate::db::ContextDb;
16
use anyhow::Result;
27
use console::style;
38
use std::collections::{HashMap, HashSet};
49
use std::fs::{self, File};
510
use std::io::Write;
611
use std::path::Path;
7-
use crate::core::embedding::EmbeddingEngine;
8-
use crate::core::graph::DependencyGraph;
9-
use crate::core::symbol::SymbolRef;
10-
use crate::core::vector_store::VectorStore;
11-
use crate::db::ContextDb;
1212

1313
pub struct ContextGenerator;
1414

@@ -22,7 +22,10 @@ impl ContextGenerator {
2222
}
2323

2424
if !db_dir.exists() {
25-
eprintln!("{}", style("Error: Database not found. Run 'amdb init' first.").red());
25+
eprintln!(
26+
"{}",
27+
style("Error: Database not found. Run 'amdb init' first.").red()
28+
);
2629
std::process::exit(1);
2730
}
2831

@@ -49,7 +52,10 @@ impl ContextGenerator {
4952
for file in &all_files {
5053
if let Ok(symbols) = db.get_symbols(file) {
5154
for sym in symbols {
52-
symbol_to_files.entry(sym.name).or_default().push(file.clone());
55+
symbol_to_files
56+
.entry(sym.name)
57+
.or_default()
58+
.push(file.clone());
5359
}
5460
}
5561
}
@@ -61,13 +67,25 @@ impl ContextGenerator {
6167
let safe_name = query.replace(" ", "-").replace("/", "-").to_lowercase();
6268
output_filename = format!("{}.md", safe_name);
6369

64-
println!("{}", style(format!("Filtering context for: '{}' with depth {}...", query, depth)).cyan());
70+
println!(
71+
"{}",
72+
style(format!(
73+
"Filtering context for: '{}' with depth {}...",
74+
query, depth
75+
))
76+
.cyan()
77+
);
6578

6679
let embedder = EmbeddingEngine::new()?;
67-
let paths = Self::resolve_focus_targets(db_dir, &all_files, &db, query, &embedder, &graph).await?;
80+
let paths =
81+
Self::resolve_focus_targets(db_dir, &all_files, &db, query, &embedder, &graph)
82+
.await?;
6883

6984
if paths.is_empty() {
70-
println!("{}", style("No matches found. Falling back to full context.").yellow());
85+
println!(
86+
"{}",
87+
style("No matches found. Falling back to full context.").yellow()
88+
);
7189
target_files = all_files;
7290
} else {
7391
let mut file_graph: HashMap<String, HashSet<String>> = HashMap::new();
@@ -76,7 +94,10 @@ impl ContextGenerator {
7694
if let Some(callee_files) = symbol_to_files.get(&edge.callee) {
7795
for callee_file in callee_files {
7896
if caller_file != callee_file {
79-
file_graph.entry(caller_file.clone()).or_default().insert(callee_file.clone());
97+
file_graph
98+
.entry(caller_file.clone())
99+
.or_default()
100+
.insert(callee_file.clone());
80101
}
81102
}
82103
}
@@ -107,7 +128,12 @@ impl ContextGenerator {
107128
let mut file = File::create(&output_path)?;
108129
file.write_all(content.as_bytes())?;
109130

110-
println!("{}", style(format!("Generated: {}", output_path.display())).green().bold());
131+
println!(
132+
"{}",
133+
style(format!("Generated: {}", output_path.display()))
134+
.green()
135+
.bold()
136+
);
111137
Ok(())
112138
}
113139

@@ -127,7 +153,9 @@ impl ContextGenerator {
127153
let file_stem = path_obj.file_stem().unwrap_or_default().to_string_lossy();
128154

129155
if file_name.eq_ignore_ascii_case(query) || file_stem.eq_ignore_ascii_case(query) {
130-
if !paths.contains(file) { paths.push(file.clone()); }
156+
if !paths.contains(file) {
157+
paths.push(file.clone());
158+
}
131159
} else if let Ok(symbols) = db.get_symbols(file) {
132160
if symbols.iter().any(|s| s.name.eq_ignore_ascii_case(query))
133161
&& !paths.contains(file)
@@ -200,7 +228,9 @@ impl ContextGenerator {
200228
content.push_str("## File Summaries\n\n");
201229
for file_path in target_files {
202230
let symbols = db.get_symbols(file_path)?;
203-
if symbols.is_empty() { continue; }
231+
if symbols.is_empty() {
232+
continue;
233+
}
204234

205235
content.push_str(&format!("### {}\n", file_path));
206236

src/core/indexer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,14 @@ impl Indexer {
201201

202202
match embedder.embed(&text) {
203203
Ok(embedding) => {
204-
let sym = SymbolRef::new(stored_path.clone(), symbol.name.clone());
204+
let sym =
205+
SymbolRef::new(stored_path.clone(), symbol.name.clone());
205206
vectors.push((sym, text, embedding));
206207
}
207-
Err(e) => warn!("Failed to embed symbol {} in {}: {}", symbol.name, stored_path, e),
208+
Err(e) => warn!(
209+
"Failed to embed symbol {} in {}: {}",
210+
symbol.name, stored_path, e
211+
),
208212
}
209213
}
210214

src/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ pub mod indexer;
66
pub mod languages;
77
pub mod parser;
88
pub mod symbol;
9-
pub mod vector_store;
9+
pub mod vector_store;

src/core/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ lazy_static! {
3131
),
3232
(
3333
"Hardcoded JWT",
34-
Regex::new(r"ey[A-Za-z0-9-_]{20,}\.[A-Za-z0-9-_]{20,}\.[A-Za-z0-9-_.+/=]{20,}").unwrap()
34+
Regex::new(r"ey[A-Za-z0-9-_]{20,}\.[A-Za-z0-9-_]{20,}\.[A-Za-z0-9-_.+/=]{20,}")
35+
.unwrap()
3536
),
3637
];
3738
}

src/core/vector_store.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use crate::core::graph::DependencyGraph;
2+
use crate::core::symbol::SymbolRef;
13
use anyhow::Result;
4+
use rayon::prelude::*;
25
use rusqlite::{params, Connection};
36
use serde::{Deserialize, Serialize};
4-
use rayon::prelude::*;
57
use std::cmp::Ordering;
6-
use std::path::Path;
78
use std::collections::HashSet;
8-
use crate::core::graph::DependencyGraph;
9-
use crate::core::symbol::SymbolRef;
9+
use std::path::Path;
1010

1111
#[derive(Debug, Clone, Serialize, Deserialize)]
1212
pub struct VectorRecord {
@@ -56,12 +56,13 @@ impl VectorStore {
5656
PRAGMA synchronous = NORMAL;",
5757
)?;
5858

59-
let had_name_column = conn
60-
.prepare("SELECT name FROM vectors LIMIT 1")
61-
.is_ok();
59+
let had_name_column = conn.prepare("SELECT name FROM vectors LIMIT 1").is_ok();
6260

6361
if !had_name_column {
64-
conn.execute("ALTER TABLE vectors ADD COLUMN name TEXT NOT NULL DEFAULT ''", [])?;
62+
conn.execute(
63+
"ALTER TABLE vectors ADD COLUMN name TEXT NOT NULL DEFAULT ''",
64+
[],
65+
)?;
6566
conn.execute("DELETE FROM vectors", [])?;
6667
}
6768

@@ -97,8 +98,15 @@ impl VectorStore {
9798
Ok(())
9899
}
99100

100-
pub fn search(&self, query_vec: &[f32], limit: usize, graph: Option<&DependencyGraph>) -> Result<Vec<(f64, VectorRecord)>> {
101-
let mut stmt = self.conn.prepare("SELECT id, file_path, name, text, vector FROM vectors")?;
101+
pub fn search(
102+
&self,
103+
query_vec: &[f32],
104+
limit: usize,
105+
graph: Option<&DependencyGraph>,
106+
) -> Result<Vec<(f64, VectorRecord)>> {
107+
let mut stmt = self
108+
.conn
109+
.prepare("SELECT id, file_path, name, text, vector FROM vectors")?;
102110

103111
let mut rows = stmt.query([])?;
104112
let mut records = Vec::new();
@@ -112,13 +120,20 @@ impl VectorStore {
112120
records.push((id, file_path, name, text, vector_blob));
113121
}
114122

115-
let mut evaluated: Vec<SearchCandidate> = records.into_par_iter()
123+
let mut evaluated: Vec<SearchCandidate> = records
124+
.into_par_iter()
116125
.filter_map(|(id, file_path, name, text, vector_blob)| {
117126
if let Ok(vector) = bincode::deserialize::<Vec<f32>>(&vector_blob) {
118127
let score = cosine_similarity(query_vec, &vector);
119128
Some(SearchCandidate {
120129
score,
121-
record: VectorRecord { id, file_path, name, text, vector }
130+
record: VectorRecord {
131+
id,
132+
file_path,
133+
name,
134+
text,
135+
vector,
136+
},
122137
})
123138
} else {
124139
None
@@ -127,13 +142,16 @@ impl VectorStore {
127142
.collect();
128143

129144
if let Some(g) = graph {
130-
evaluated.sort_unstable_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(Ordering::Equal));
145+
evaluated
146+
.sort_unstable_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(Ordering::Equal));
131147

132148
let mut top_syms = HashSet::new();
133149
let mut top_names = HashSet::new();
134150

135151
for (i, cand) in evaluated.iter().enumerate() {
136-
if i >= 5 { break; }
152+
if i >= 5 {
153+
break;
154+
}
137155
top_syms.insert(cand.record.symbol());
138156
top_names.insert(cand.record.name.clone());
139157
}
@@ -169,7 +187,8 @@ impl VectorStore {
169187
}
170188

171189
pub fn save(&self, _path: &Path) -> Result<()> {
172-
self.conn.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);")?;
190+
self.conn
191+
.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);")?;
173192
Ok(())
174193
}
175194
}
@@ -182,4 +201,4 @@ fn cosine_similarity(a: &[f32], b: &[f32]) -> f64 {
182201
return 0.0;
183202
}
184203
(dot_product / (norm_a * norm_b)) as f64
185-
}
204+
}

src/db/query.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ impl ContextDb {
2222

2323
let needs_reindex = schema::init(&conn)?;
2424

25-
Ok(Self { conn, needs_reindex })
25+
Ok(Self {
26+
conn,
27+
needs_reindex,
28+
})
2629
}
2730

2831
pub fn save_symbols(&mut self, file_path: &str, symbols: &[CodeSymbol]) -> Result<()> {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ async fn main() -> anyhow::Result<()> {
8383
}
8484
}
8585
Ok(())
86-
}
86+
}

0 commit comments

Comments
 (0)