From 6abc9964d9611c557d81c0b34733a22096523ed7 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 27 Oct 2022 23:56:22 +0900 Subject: [PATCH 1/3] Add PHPStan and Psalm type names to php-phpdoc-type-keywords --- lisp/php-mode.el | 10 +++++++++- tests/lang/doc-comment/return-type.php.faces | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 241e2c96..82ee54db 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1279,7 +1279,15 @@ for \\[find-tag] (which see)." (list "string" "integer" "int" "boolean" "bool" "float" "double" "object" "mixed" "array" "resource" "void" "null" "false" "true" "self" "static" - "callable" "iterable" "number")) + "callable" "iterable" "number" + ;; PHPStan and Psalm types + "array-key" "associative-array" "callable-array" "callable-object" + "callable-string" "class-string" "empty" "enum-string" "list" + "literal-string" "negative-int" "non-positive-int" "non-negative-int" + "never" "never-return" "never-returns" "no-return" "non-empty-array" + "non-empty-list" "non-empty-string" "non-falsy-string" + "numeric" "numeric-string" "positive-int" "scalar" + "trait-string" "truthy-string")) (defconst php-phpdoc-type-tags (list "package" "param" "property" "property-read" "property-write" diff --git a/tests/lang/doc-comment/return-type.php.faces b/tests/lang/doc-comment/return-type.php.faces index 13d08f2f..7bc8a8ec 100644 --- a/tests/lang/doc-comment/return-type.php.faces +++ b/tests/lang/doc-comment/return-type.php.faces @@ -32,7 +32,9 @@ (" " . font-lock-doc-face) ("int" font-lock-type-face php-string font-lock-doc-face) ("[]" php-string font-lock-doc-face) - (" A list of " . font-lock-doc-face) + (" A " . font-lock-doc-face) + ("list" font-lock-type-face font-lock-doc-face) + (" of " . font-lock-doc-face) ("integer" font-lock-type-face font-lock-doc-face) (" values */" . font-lock-doc-face) ("\n\n\n") @@ -59,7 +61,9 @@ ("@return" php-doc-annotation-tag font-lock-doc-face) (" " . font-lock-doc-face) ("DateTime[]" php-string font-lock-doc-face) - (" A list of DateTime " . font-lock-doc-face) + (" A " . font-lock-doc-face) + ("list" font-lock-type-face font-lock-doc-face) + (" of DateTime " . font-lock-doc-face) ("object" font-lock-type-face font-lock-doc-face) (" values */" . font-lock-doc-face) ("\n\n\n") @@ -86,7 +90,9 @@ ("@return" php-doc-annotation-tag font-lock-doc-face) (" " . font-lock-doc-face) ("stdClass[]" php-string font-lock-doc-face) - (" A list of stdClass " . font-lock-doc-face) + (" A " . font-lock-doc-face) + ("list" font-lock-type-face font-lock-doc-face) + (" of stdClass " . font-lock-doc-face) ("object" font-lock-type-face font-lock-doc-face) (" values */" . font-lock-doc-face) ("\n\n") @@ -113,7 +119,9 @@ ("@return" php-doc-annotation-tag font-lock-doc-face) (" " . font-lock-doc-face) ("\\App\\User[]" php-string font-lock-doc-face) - (" A list of \\App\\User " . font-lock-doc-face) + (" A " . font-lock-doc-face) + ("list" font-lock-type-face font-lock-doc-face) + (" of \\App\\User " . font-lock-doc-face) ("object" font-lock-type-face font-lock-doc-face) (" values */" . font-lock-doc-face) ("\n\n") @@ -138,7 +146,9 @@ ("int" font-lock-type-face php-string font-lock-doc-face) ("[]|" php-string font-lock-doc-face) ("string" font-lock-type-face php-string font-lock-doc-face) - (" Multiple types by list of " . font-lock-doc-face) + (" Multiple types by " . font-lock-doc-face) + ("list" font-lock-type-face font-lock-doc-face) + (" of " . font-lock-doc-face) ("int" font-lock-type-face font-lock-doc-face) (" and " . font-lock-doc-face) ("string" font-lock-type-face font-lock-doc-face) From fa8a969bb1e7e2a2723a0d146fb71a2602662877 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Fri, 28 Oct 2022 00:02:17 +0900 Subject: [PATCH 2/3] Support prefixed tags in phpstan- and psalm- --- lisp/php-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 82ee54db..e1ee50d8 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1301,7 +1301,7 @@ for \\[find-tag] (which see)." (1 'php-doc-variable-sigil prepend nil) (2 'php-variable-name prepend nil)) ("\\(\\$\\)\\(this\\)\\>" (1 'php-doc-$this-sigil prepend nil) (2 'php-doc-$this prepend nil)) - (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" + (,(concat "\\s-@" (rx (? (or "phpstan" "psalm") "-")) (regexp-opt php-phpdoc-type-tags) "\\s-+" "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") 1 'php-string prepend nil) (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\(" From 9424e19eb5b2916b5e4fe1ab70b9408734f78462 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Fri, 28 Oct 2022 00:05:09 +0900 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 426174e3..27b4cbde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * **New feature: `php-complete`** * Add `php-complete-complete-function` to autocomplete function names ([#708]) + * Supports PHPDoc tags and types for static analysis tools ([#710]) ### Changed @@ -22,6 +23,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this [#704]: https://github.com/emacs-php/php-mode/pull/704 [#707]: https://github.com/emacs-php/php-mode/pull/707 [#708]: https://github.com/emacs-php/php-mode/pull/708 +[#710]: https://github.com/emacs-php/php-mode/pull/710 ## [1.24.1] - 2022-10-08