pub mod python;
pub mod rust;
pub mod typescript;
use std::path::Path;
use serde::Serialize;
use crate::errors::Result;
#[derive(Debug, Clone, Serialize)]
pub struct Diagnostic {
pub file: String,
pub line_start: u32,
pub line_end: u32,
pub level: String,
pub code: String,
pub message: String,
pub driver: &'static str,
}
#[derive(Debug, Clone)]
pub enum Scope {
Workspace,
Package { name: String },
File { path: String },
}
pub trait Driver {
fn name(&self) -> &'static str;
fn detect(&self, project_root: &Path) -> bool;
fn run<'a>(
&'a self,
project_root: &'a Path,
scope: &'a Scope,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<Diagnostic>>> + Send + 'a>>;
}
pub async fn run_all(project_root: &Path, scope: &Scope) -> Result<Vec<Diagnostic>> {
let drivers: Vec<Box<dyn Driver + Send + Sync>> = vec![
Box::new(rust::CargoDriver),
Box::new(typescript::TscDriver),
Box::new(python::PyrightDriver),
];
let mut all = Vec::new();
for driver in drivers {
if !driver.detect(project_root) {
continue;
}
let mut diags = driver.run(project_root, scope).await?;
all.append(&mut diags);
}
Ok(all)
}