From d4a2a84c361e2248e50368b87d37870ab3f98bab Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 3 Dec 2026 16:06:52 +0100 Subject: [PATCH] fix(php): give PHPantom the template, configuration and settings support it has (#7827) PHPantom has its own Blade, Twig and framework support, but Twig, YAML and XML files were never sent to it, laravel-lsp kept running alongside it, and it was never told the project is trusted. PHPantom now joins twig, yaml and xml (XML limited to *.xml, *.xlf, *.xliff), replaces laravel-lsp, gets .phpantom.toml as a root marker, and configure_phpantom sends workspaceTrusted (servers only start outside Restricted Mode) plus the excluded folders and PHP file-type extensions as its indexing filters at startup and on every configuration change. Docs updated. Co-authored-by: AJenbo <204594+AJenbo@users.noreply.github.com> --- crates/ide-language/src/registry.rs | 28 +++++++++++++++++++- crates/ide-sdk/src/apply.rs | 3 +++ crates/ide-sdk/src/php.rs | 26 ++++++++++++++++++ crates/ide-sdk/src/tests.rs | 41 +++++++++++++++++++++++++++++ docs/en/languages/index.mdx | 6 ++--- docs/en/languages/php.mdx | 26 +++++++++++++----- docs/zh/languages/index.mdx | 6 ++--- docs/zh/languages/php.mdx | 26 +++++++++++++----- languages/blade.toml | 6 +++-- languages/php.toml | 4 ++- languages/twig.toml | 11 ++++++++ languages/xml.toml | 11 ++++++++ languages/yaml.toml | 11 ++++++++ 13 files changed, 183 insertions(+), 22 deletions(-) diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs index ff18ed8e8e..c04837244b 100644 --- a/crates/ide-language/src/registry.rs +++ b/crates/ide-language/src/registry.rs @@ -1168,12 +1168,38 @@ mod tests { // No other language starts a PHP server. for lang in reg.all() { for server in lang.language_servers.iter().filter(|s| s.joins.is_some()) { - assert_eq!((server.name.as_str(), server.joins.as_deref()), ("phoxite", Some("php")), "{}", lang.id); + assert!(["phoxite", "phpantom"].contains(&server.name.as_str()), "{}: {}", lang.id, server.name); + assert_eq!(server.joins.as_deref(), Some("php"), "{}", lang.id); } } assert!(php.language_servers.iter().all(|s| s.joins.is_none() && s.files.is_empty())); } + #[test] + fn phpantom_reads_templates_and_configuration_where_it_serves_php() { + let reg = reg(); + let php = reg.get(&LanguageId::new("php")).unwrap(); + let of_php = php.language_servers.iter().find(|s| s.name == "phpantom").unwrap(); + // It answers the Laravel strings itself. + assert_eq!(of_php.replaces, ["laravel-lsp"]); + // Only the XML it reads: an SVG would be parsed as PHP. + let xml = &["**/*.xml", "**/*.xlf", "**/*.xliff"][..]; + for (language, files) in [("twig", &[][..]), ("yaml", &[][..]), ("xml", xml)] { + let cfg = reg.get(&LanguageId::new(language)).unwrap(); + let phpantom = cfg.language_servers.iter().find(|s| s.name == "phpantom").unwrap(); + assert_eq!(phpantom.joins.as_deref(), Some("php"), "{language}"); + assert_eq!(phpantom.files, files, "{language}"); + assert_eq!( + (&phpantom.command, &phpantom.args, &phpantom.root_markers), + (&of_php.command, &of_php.args, &of_php.root_markers), + "{language}" + ); + } + let blade = reg.get(&LanguageId::new("blade")).unwrap(); + let of_blade = blade.language_servers.iter().find(|s| s.name == "phpantom").unwrap(); + assert_eq!((&of_blade.root_markers, &of_blade.replaces), (&of_php.root_markers, &of_php.replaces)); + } + #[test] fn pylsp_adds_only_rope_refactorings_to_python() { let reg = reg(); diff --git a/crates/ide-sdk/src/apply.rs b/crates/ide-sdk/src/apply.rs index 7278617d77..3212c583de 100644 --- a/crates/ide-sdk/src/apply.rs +++ b/crates/ide-sdk/src/apply.rs @@ -1550,6 +1550,9 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root if name == "phoxite" { crate::php::configure_phoxite(cfg, root, s); } + if name == "phpantom" { + crate::php::configure_phpantom(cfg, s); + } // Node-based servers (`#!/usr/bin/env node`) run on the selected Node.js. if let Some(dir) = node_dir(root, s) { diff --git a/crates/ide-sdk/src/php.rs b/crates/ide-sdk/src/php.rs index e798c08325..76b9567fe9 100644 --- a/crates/ide-sdk/src/php.rs +++ b/crates/ide-sdk/src/php.rs @@ -229,6 +229,32 @@ pub fn configure_phoxite(cfg: &mut LanguageServerConfig, root: &Path, s: &Settin cfg.settings = Some(settings); } +/// What PHPantom reads from the editor. It only starts in a trusted project, so it is told +/// that, and runs the project's PHPStan, PHP_CodeSniffer and formatters without asking again. +/// The excluded folders and the extensions added to PHP in Settings › File Types become its +/// `indexing` filters, which it adds to those of the project's `.phpantom.toml`. It reads the +/// PHP version from `composer.json` or `.phpantom.toml` itself. +/// +/// The filters are sent at startup and, under `phpantom`, with every +/// `workspace/didChangeConfiguration`, so a change applies without a restart. +pub fn configure_phpantom(cfg: &mut LanguageServerConfig, s: &Settings) { + let extensions: Vec = s + .files + .file_types + .get("php") + .into_iter() + .flat_map(|php| &php.patterns) + .filter_map(|pattern| pattern.trim().strip_prefix("*.")) + .filter(|ext| !ext.is_empty() && !ext.contains(['.', '*', '?', '/', '\\'])) + .map(str::to_owned) + .collect(); + let indexing = json!({ "exclude": s.exclude_globs(), "extensions": extensions }); + merge_init_options(cfg, json!({ "workspaceTrusted": true, "indexing": indexing.clone() })); + let mut settings = cfg.settings.take().filter(Value::is_object).unwrap_or_else(|| json!({})); + merge(&mut settings, json!({ "phpantom": { "indexing": indexing } })); + cfg.settings = Some(settings); +} + /// `vendor/bin/phpstan analyse` of `files` with a JSON report and the configuration file of /// Settings › PHP, run from `root` with Xdebug off: in debug mode it would try to reach a /// debugger on every run. The selected PHP runs the script itself (and is first on `PATH`, as for diff --git a/crates/ide-sdk/src/tests.rs b/crates/ide-sdk/src/tests.rs index dc5e96c26e..4f3c23ed86 100644 --- a/crates/ide-sdk/src/tests.rs +++ b/crates/ide-sdk/src/tests.rs @@ -3338,6 +3338,47 @@ fn phoxite_gets_the_php_settings_at_startup_and_on_every_configuration_change() assert_eq!(other.settings, None); } +#[test] +fn phpantom_is_trusted_and_gets_the_file_filters_at_startup_and_on_every_configuration_change() { + use serde_json::json; + let tmp = tempfile::tempdir().unwrap(); + let mut s = Settings::default(); + s.project_structure.excluded = vec!["storage/".into()]; + s.files.file_types.insert( + "php".into(), + ide_core::settings::FileTypeAssociation { + // Only the patterns that name an extension: `inc`, `module`. + patterns: vec![ + "*.inc".into(), + " *.module ".into(), + "*.blade.php".into(), + "Jenkinsfile".into(), + "*.".into(), + ], + ..Default::default() + }, + ); + let mut cfg = server("phpantom"); + configure_server(&mut cfg, tmp.path(), tmp.path(), &s); + let options = serde_json::to_value(&cfg.initialization_options).unwrap(); + assert_eq!(options["workspaceTrusted"], json!(true)); + let indexing = &options["indexing"]; + assert_eq!(indexing["extensions"], json!(["inc", "module"])); + assert_eq!(indexing["exclude"], json!(s.exclude_globs())); + assert!(s.exclude_globs().contains(&"/storage".to_owned())); + // What `workspace/didChangeConfiguration` carries: PHPantom reads the `phpantom` section. + assert_eq!(cfg.settings, Some(json!({"phpantom": {"indexing": indexing}}))); + + // An empty list is sent too: it clears what an earlier notification set. + let mut cfg = server("phpantom"); + configure_server(&mut cfg, tmp.path(), tmp.path(), &Settings::default()); + assert_eq!(cfg.settings.unwrap()["phpantom"]["indexing"]["extensions"], json!([])); + + let mut other = server("phoxite"); + configure_server(&mut other, tmp.path(), tmp.path(), &s); + assert_eq!(other.settings, None); +} + #[test] fn go_constraints_change_only_protocol_settings() { use serde_json::json; diff --git a/docs/en/languages/index.mdx b/docs/en/languages/index.mdx index 87a1b74dab..922e7c5b39 100644 --- a/docs/en/languages/index.mdx +++ b/docs/en/languages/index.mdx @@ -178,14 +178,14 @@ The table lists every built-in language definition. Server and debugger names in | Terraform | `terraform` | `.tf`, `.tofu`, `.tftest.hcl` | Yes | Yes | **terraform-ls** | — | | Terraform Variables | `terraform-vars` | `.tfvars` | Yes | Yes | **terraform-ls** | — | | TOML | `toml` | `.toml` | Yes | Yes | **taplo** | — | -| Twig | `twig` | `.twig` | Yes | — | **phoxite** (with PHP) | — | +| Twig | `twig` | `.twig` | Yes | — | **phpantom** or **phoxite** (with PHP) | — | | TypeScript | `typescript` | `.ts`, `.mts`, `.cts` | Yes | Yes | **vtsls** → **typescript-language-server** + **angular-language-server** + **oxlint** + **biome** | **js-debug** | | TypeScript JSX | `typescriptreact` | `.tsx` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | | Typst | `typst` | `.typ` | — | — | **tinymist** | — | | Vue | `vue` | `.vue` | Yes | — | **vue-language-server**, **vtsls** + **oxlint** | — | | Xcode Config | `xcconfig` | `.xcconfig` | Yes | — | — | — | -| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | Yes | Yes | **lemminx** | — | -| YAML | `yaml` | `.yaml`, `.yml` | Yes | Yes | **yaml-language-server** | — | +| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | Yes | Yes | **lemminx** + **phpantom** (with PHP) | — | +| YAML | `yaml` | `.yaml`, `.yml` | Yes | Yes | **yaml-language-server** + **phpantom** (with PHP) | — | | Zig | `zig` | `.zig`, `.zon` | Yes | Yes | **zls** | **codelldb** | Notes: diff --git a/docs/en/languages/php.mdx b/docs/en/languages/php.mdx index 60e0ee8381..895e061167 100644 --- a/docs/en/languages/php.mdx +++ b/docs/en/languages/php.mdx @@ -1,6 +1,6 @@ --- title: "PHP" -description: "Intelephense and Phoxite, PHP interpreters and language level, Composer, PHPUnit and Pest, PHPStan, Xdebug debugging, Blade and Twig templates, and Laravel, Symfony and other framework support." +description: "Intelephense, PHPantom and Phoxite, PHP interpreters and language level, Composer, PHPUnit and Pest, PHPStan, Xdebug debugging, Blade and Twig templates, and Laravel, Symfony and other framework support." --- OpenIDEA highlights PHP files (`.php`, `.phtml`, `.phpt` and older `.php3`–`.php5`, plus files starting with `