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.
7#[cfg(not(target_family = "wasm"))]
8pub mod phpcs;
9#[cfg(not(target_family = "wasm"))]
10pub mod phpstan;
11
12#[cfg(not(target_family = "wasm"))]
13use std::path::Path;
14
15#[cfg(not(target_family = "wasm"))]
16use tower_lsp_server::ls_types::Diagnostic;
17
18#[cfg(not(target_family = "wasm"))]
19use crate::lang::config::ExternalToolsConfig;
20
21/// Run every enabled external tool against `path` and return their combined
22/// diagnostics. Tools run one after another rather than concurrently so a
23/// single caller gets one complete `Vec` back instead of having to merge two
24/// independently-arriving results.
25#[cfg(not(target_family = "wasm"))]
26pub async fn run_external_diagnostics(
27    cfg: &ExternalToolsConfig,
28    path: &Path,
29    workspace_root: Option<&Path>,
30) -> Vec<Diagnostic> {
31    let mut out = Vec::new();
32    if cfg.phpstan.enabled {
33        out.extend(phpstan::run(&cfg.phpstan, path, workspace_root).await);
34    }
35    if cfg.phpcs.enabled {
36        out.extend(phpcs::run(&cfg.phpcs, path, workspace_root).await);
37    }
38    out
39}