Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports PHPDoc tags and types for static analysis tools #710

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
12 changes: 10 additions & 2 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -1293,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-\\)\\("
Expand Down
20 changes: 15 additions & 5 deletions tests/lang/doc-comment/return-type.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand Down