From bd265fee7e9655e2898e6f6b76267eb832b0f3c9 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Wed, 11 Feb 2026 13:34:16 +0100 Subject: [PATCH] languages/php: add formatting (#1401) --- docs/manual/release-notes/rl-0.9.md | 3 ++ modules/plugins/languages/php.nix | 44 +++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 967609dc..2ff72acd 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -176,6 +176,9 @@ - Added Debugging support to `languages.php`. +- Added Formatting support to `languages.php` via + [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer). + - Didn't Add [`syntax-gaslighting`](https://github.com/NotAShelf/syntax-gaslighting.nvim), you're crazy. diff --git a/modules/plugins/languages/php.nix b/modules/plugins/languages/php.nix index dc859a4f..8d2af124 100644 --- a/modules/plugins/languages/php.nix +++ b/modules/plugins/languages/php.nix @@ -4,11 +4,11 @@ lib, ... }: let - inherit (builtins) attrNames toString toFile; + inherit (builtins) attrNames toString; inherit (lib.options) mkEnableOption mkOption; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum int attrs; + inherit (lib.types) enum int attrs listOf; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; @@ -65,6 +65,21 @@ root_markers = ["composer.json" ".git"]; }; }; + + defaultFormat = ["php_cs_fixer"]; + formats = { + php_cs_fixer = { + /* + Using 8.4 instead of 8.5 because of compatibility: + ```logs + 2026-02-08 00:42:23[ERROR] Formatter 'php_cs_fixer' error: PHP CS Fixer 3.87.2 + PHP runtime: 8.5.2 + PHP CS Fixer currently supports PHP syntax only up to PHP 8.4, current PHP version: 8.5.2. + ``` + */ + command = "${pkgs.php84Packages.php-cs-fixer}/bin/php-cs-fixer"; + }; + }; in { options.vim.languages.php = { enable = mkEnableOption "PHP language support"; @@ -84,6 +99,16 @@ in { }; }; + format = { + enable = mkEnableOption "PHP formatting" // {default = config.vim.languages.enableFormat;}; + + type = mkOption { + description = "PHP formatter to use"; + type = listOf (enum (attrNames formats)); + default = defaultFormat; + }; + }; + dap = { enable = mkEnableOption "Enable PHP Debug Adapter" // {default = config.vim.languages.enableDAP;}; xdebug = { @@ -122,6 +147,21 @@ in { cfg.lsp.servers; }) + (mkIf cfg.format.enable { + vim.formatter.conform-nvim = { + enable = true; + setupOpts = { + formatters_by_ft.php = cfg.format.type; + formatters = + mapListToAttrs (name: { + inherit name; + value = formats.${name}; + }) + cfg.format.type; + }; + }; + }) + (mkIf cfg.dap.enable { vim = { debugger.nvim-dap = {