From a9e08e15d7edc015b664a984815dfdcc2f358d06 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 18 Sep 2025 15:04:06 -0400 Subject: [PATCH] fix(php): treesit: PSR-2 indentation for chained methods Before: public function someMethod() { return $this->doSomething() ->doSomethingElse() ->andDoOneLastThing(); } After: public function someMethod() { return $this->doSomething() ->doSomethingElse() ->andDoOneLastThing(); } Fix: doomemacs/community#36 --- modules/lang/php/config.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/lang/php/config.el b/modules/lang/php/config.el index 00c012eb1..6f4a33c08 100644 --- a/modules/lang/php/config.el +++ b/modules/lang/php/config.el @@ -82,7 +82,23 @@ html css ; requires :lang (web +tree-sitter) javascript jsdoc)) ; requires :lang (javascript +tree-sitter) :config - (+php-common-config 'php-ts-mode)) + (+php-common-config 'php-ts-mode) + + ;; HACK: This advice fixes PSR-2/12 indentation of chained methods and makes + ;; room for any future corrections. + ;; REVIEW: PR these corrections upstream. + (defadvice! +php--correct-indent-styles-a (fn &rest args) + :around #'php-ts-mode--get-indent-style + (let ((rules (apply fn args))) + (if (functionp php-ts-mode-indent-style) + rules + `((php + ,@(pcase php-ts-mode-indent-style + (`psr2 + `(((parent-is "member_call_expression") parent-bol php-ts-mode-indent-offset))) + ;; Room for other corrections + ) + ,@(cadr rules))))))) (use-package! php-refactor-mode