languages/php: add formatting (#1401)
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Treewide Checks / Validate flake (push) Has been cancelled
Treewide Checks / Check formatting (push) Has been cancelled
Treewide Checks / Check source tree for typos (push) Has been cancelled
Treewide Checks / Validate documentation builds (push) Has been cancelled
Treewide Checks / Validate documentation builds-1 (push) Has been cancelled
Treewide Checks / Validate documentation builds-2 (push) Has been cancelled
Treewide Checks / Validate documentation builds-3 (push) Has been cancelled
Treewide Checks / Validate hyperlinks in documentation sources (push) Has been cancelled
Treewide Checks / Validate Editorconfig conformance (push) Has been cancelled
Build and deploy documentation / Check latest commit (push) Has been cancelled
Build and deploy documentation / publish (push) Has been cancelled

This commit is contained in:
Snoweuph 2026-02-11 13:34:16 +01:00 committed by GitHub
commit bd265fee7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 2 deletions

View file

@ -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.

View file

@ -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 = {