Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/analysis/ast_cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use syn::File as SynFile;
use walkdir::WalkDir;

Expand Down Expand Up @@ -33,6 +33,15 @@ impl AstCache {
}
}

fn should_skip_path(path: &Path) -> bool {
path.components().any(|component| {
component
.as_os_str()
.to_str()
.is_some_and(|part| part == "target" || part == ".git")
})
}

/// Parse and cache all Rust files in the given project path
pub fn parse_and_cache_all_files(
&mut self,
Expand All @@ -47,14 +56,11 @@ impl AstCache {
let entry = entry?;
let path = entry.path();

if path.is_file() && path.extension().is_some_and(|ext| ext == "rs") {
// Skip target directory and other build artifacts
if path.to_string_lossy().contains("/target/")
|| path.to_string_lossy().contains("/.git/")
{
continue;
}
if Self::should_skip_path(path) {
continue;
}

if path.is_file() && path.extension().is_some_and(|ext| ext == "rs") {
if verbose {
println!("📄 Parsing file: {}", path.display());
}
Expand Down
19 changes: 9 additions & 10 deletions src/analysis/dependency_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ impl TypeDependencyGraph {
let mut sorted = Vec::new();
let mut visited = HashSet::new();
let mut visiting = HashSet::new();
let mut type_names: Vec<&String> = types.iter().collect();
type_names.sort_unstable();

for type_name in types {
for type_name in type_names {
if !visited.contains(type_name) {
self.topological_visit(type_name, &mut sorted, &mut visited, &mut visiting);
}
Expand Down Expand Up @@ -101,7 +103,10 @@ impl TypeDependencyGraph {

// Visit dependencies first
if let Some(deps) = self.dependencies.get(type_name) {
for dep in deps {
let mut sorted_deps: Vec<&String> = deps.iter().collect();
sorted_deps.sort_unstable();

for dep in sorted_deps {
self.topological_visit(dep, sorted, visited, visiting);
}
}
Expand Down Expand Up @@ -390,9 +395,7 @@ mod tests {
types.insert("Post".to_string());

let sorted = graph.topological_sort_types(&types);
assert_eq!(sorted.len(), 2);
assert!(sorted.contains(&"User".to_string()));
assert!(sorted.contains(&"Post".to_string()));
assert_eq!(sorted, vec!["Post", "User"]);
}

#[test]
Expand Down Expand Up @@ -433,11 +436,7 @@ mod tests {
assert_eq!(sorted[0], "A");
// D must come last (depends on everything)
assert_eq!(sorted[3], "D");
// B and C can be in either order but after A and before D
let b_pos = sorted.iter().position(|x| x == "B").unwrap();
let c_pos = sorted.iter().position(|x| x == "C").unwrap();
assert!(b_pos > 0 && b_pos < 3);
assert!(c_pos > 0 && c_pos < 3);
assert_eq!(sorted, vec!["A", "B", "C", "D"]);
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ impl CommandAnalyzer {
.parse_and_cache_all_files(project_path, verbose)?;

// Extract commands from cached ASTs
let file_paths: Vec<PathBuf> = self.ast_cache.keys().cloned().collect();
let mut file_paths: Vec<PathBuf> = self.ast_cache.keys().cloned().collect();
file_paths.sort_unstable();
let mut commands = Vec::new();
let mut type_names_to_discover = HashSet::new();

Expand Down
4 changes: 3 additions & 1 deletion src/bin/cargo-tauri-typegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ fn run_generate(

// Check cache to see if regeneration is needed (unless force is set)
let discovered_structs = analyzer.get_discovered_structs();
let discovered_events = analyzer.get_discovered_events();
let needs_regeneration = if config.should_force() {
if config.is_verbose() {
println!("🔄 Force flag set, regenerating bindings");
Expand All @@ -225,6 +226,7 @@ fn run_generate(
&config.output_path,
&commands,
discovered_structs,
discovered_events,
&config,
)
.unwrap_or(true) // On error, assume regeneration is needed
Expand Down Expand Up @@ -273,7 +275,7 @@ fn run_generate(
}

// Save cache after successful generation
let cache = GenerationCache::new(&commands, discovered_structs, &config)?;
let cache = GenerationCache::new(&commands, discovered_structs, discovered_events, &config)?;
if let Err(e) = cache.save(&config.output_path) {
eprintln!("Warning: Failed to save generation cache: {}", e);
}
Expand Down
Loading
Loading