Skip to main content

php_lsp/analysis/external/
mod.rs

1//! External static-analysis tool integration (PHPStan / PHPCS).
2//!
3//! These run as child processes against a single saved file and their
4//! findings are merged into the diagnostics the built-in `mir`-backed
5//! analyzer already produces — see [`crate::lang::config::ExternalToolsConfig`]
6//! for why both default off.
7pub mod phpcs;
8pub mod phpstan;
9
10use std::path::Path;
11
12use tower_lsp_server::ls_types::Diagnostic;
13
14use crate::lang::config::ExternalToolsConfig;
15
16/// Run every enabled external tool against `path` and return their combined
17/// diagnostics. Tools run one after another rather than concurrently so a
18/// single caller gets one complete `Vec` back instead of having to merge two
19/// independently-arriving results.
20pub async fn run_external_diagnostics(
21    cfg: &ExternalToolsConfig,
22    path: &Path,
23    workspace_root: Option<&Path>,
24) -> Vec<Diagnostic> {
25    let mut out = Vec::new();
26    if cfg.phpstan.enabled {
27        out.extend(phpstan::run(&cfg.phpstan, path, workspace_root).await);
28    }
29    if cfg.phpcs.enabled {
30        out.extend(phpcs::run(&cfg.phpcs, path, workspace_root).await);
31    }
32    out
33}