#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_project(
root_path: &Path,
toolchain: &str,
) -> Result<ProjectContext, TemplateError> {
analyze_project_with_cache(root_path, toolchain, None).await
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_project_for_dead_code(
root_path: &Path,
toolchain: &str,
) -> Result<ProjectContext, TemplateError> {
let gitignore = build_gitignore(root_path)?;
let files = scan_rust_files_only(root_path, toolchain, None, &gitignore).await;
let summary = build_project_summary(&files, root_path, toolchain).await;
Ok(ProjectContext {
project_type: toolchain.to_string(),
files,
summary,
graph: None,
})
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_project_with_cache(
root_path: &Path,
toolchain: &str,
cache_manager: Option<Arc<SessionCacheManager>>,
) -> Result<ProjectContext, TemplateError> {
let gitignore = build_gitignore(root_path)?;
let files = scan_and_analyze_files(root_path, toolchain, cache_manager, &gitignore).await;
let summary = build_project_summary(&files, root_path, toolchain).await;
let graph = build_context_graph(&files).ok();
Ok(ProjectContext {
project_type: toolchain.to_string(),
files,
summary,
graph,
})
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_project_with_persistent_cache(
root_path: &Path,
toolchain: &str,
cache_manager: Option<Arc<PersistentCacheManager>>,
) -> Result<ProjectContext, TemplateError> {
let gitignore = build_gitignore(root_path)?;
let files =
scan_and_analyze_files_persistent(root_path, toolchain, cache_manager, &gitignore).await;
let summary = build_project_summary(&files, root_path, toolchain).await;
Ok(ProjectContext {
project_type: toolchain.to_string(),
files,
summary,
graph: None,
})
}
async fn analyze_file_by_toolchain(
path: &Path,
_toolchain: &str,
cache_manager: Option<Arc<SessionCacheManager>>,
) -> Option<FileContext> {
let ext = path.extension().and_then(|s| s.to_str())?;
match ext {
"rs" => analyze_rust_file_with_cache(path, cache_manager).await.ok(),
#[cfg(feature = "typescript-ast")]
"ts" | "tsx" => ast_typescript::analyze_typescript_file(path).await.ok(),
#[cfg(feature = "typescript-ast")]
"js" | "jsx" | "mjs" | "cjs" => ast_typescript::analyze_javascript_file(path).await.ok(),
#[cfg(feature = "python-ast")]
"py" | "pyi" => ast_python::analyze_python_file(path).await.ok(),
#[cfg(feature = "go-ast")]
"go" => {
use crate::services::languages::go;
go::analyze_go_file(path).await.ok()
}
#[cfg(feature = "c-ast")]
"c" | "h" => {
use crate::services::ast::languages::c;
c::analyze_c_file(path).await.ok()
}
#[cfg(feature = "cpp-ast")]
"cpp" | "cc" | "cxx" | "hpp" | "hxx" | "hh" | "cu" | "cuh" => {
use crate::services::ast::languages::cpp;
cpp::analyze_cpp_file(path).await.ok()
}
#[cfg(feature = "java-ast")]
"java" => {
use crate::services::deep_context;
match deep_context::analyze_java_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "java".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
#[cfg(feature = "csharp-ast")]
"cs" => {
use crate::services::deep_context;
match deep_context::analyze_csharp_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "csharp".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
#[cfg(feature = "kotlin-ast")]
"kt" | "kts" => {
use crate::services::languages::kotlin;
kotlin::analyze_kotlin_file(path).await.ok()
}
#[cfg(feature = "swift-ast")]
"swift" => {
use crate::services::deep_context;
match deep_context::analyze_swift_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "swift".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
_ => None,
}
}
async fn analyze_deno_file(path: &Path) -> Option<FileContext> {
let ext = path.extension().and_then(|s| s.to_str());
match ext {
#[cfg(feature = "typescript-ast")]
Some("ts" | "tsx") => ast_typescript::analyze_typescript_file(path).await.ok(),
#[cfg(feature = "typescript-ast")]
Some("js" | "jsx") => ast_typescript::analyze_javascript_file(path).await.ok(),
_ => None,
}
}
async fn analyze_file_by_toolchain_persistent(
path: &Path,
_toolchain: &str,
cache_manager: Option<Arc<PersistentCacheManager>>,
) -> Option<FileContext> {
let ext = path.extension().and_then(|s| s.to_str())?;
match ext {
"rs" => analyze_rust_file_with_persistent_cache(path, cache_manager)
.await
.ok(),
#[cfg(feature = "typescript-ast")]
"ts" | "tsx" => ast_typescript::analyze_typescript_file(path).await.ok(),
#[cfg(feature = "typescript-ast")]
"js" | "jsx" | "mjs" | "cjs" => ast_typescript::analyze_javascript_file(path).await.ok(),
#[cfg(feature = "python-ast")]
"py" | "pyi" => ast_python::analyze_python_file(path).await.ok(),
#[cfg(feature = "go-ast")]
"go" => {
use crate::services::languages::go;
go::analyze_go_file(path).await.ok()
}
#[cfg(feature = "c-ast")]
"c" | "h" => {
use crate::services::ast::languages::c;
c::analyze_c_file(path).await.ok()
}
#[cfg(feature = "cpp-ast")]
"cpp" | "cc" | "cxx" | "hpp" | "hxx" | "hh" | "cu" | "cuh" => {
use crate::services::ast::languages::cpp;
cpp::analyze_cpp_file(path).await.ok()
}
#[cfg(feature = "java-ast")]
"java" => {
use crate::services::deep_context;
match deep_context::analyze_java_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "java".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
#[cfg(feature = "csharp-ast")]
"cs" => {
use crate::services::deep_context;
match deep_context::analyze_csharp_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "csharp".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
#[cfg(feature = "kotlin-ast")]
"kt" | "kts" => {
use crate::services::languages::kotlin;
kotlin::analyze_kotlin_file(path).await.ok()
}
#[cfg(feature = "swift-ast")]
"swift" => {
use crate::services::deep_context;
match deep_context::analyze_swift_file(path).await {
Ok(items) => Some(FileContext {
path: path.display().to_string(),
language: "swift".to_string(),
items,
complexity_metrics: None,
}),
Err(_) => None,
}
}
_ => None,
}
}