Skip to content

Commit

Permalink
Merge pull request #717 from emacs-php/refactor/phpdoc-type-variables
Browse files Browse the repository at this point in the history
Add PHPDoc types and rename variable name
  • Loading branch information
zonuexe authored Nov 3, 2022
2 parents fe8ab09 + 7853345 commit 865bc84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ 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])
* Supports PHPDoc tags and types for static analysis tools ([#710], [#715], [#716], [#717], thanks to [@takeokunn])
* Please refer to the article below
* PHPStan: [PHPDoc Types](https://phpstan.org/writing-php-code/phpdoc-types)
* PHPStan: [PHPDocs Basics](https://phpstan.org/writing-php-code/phpdocs-basics)
* Psalm: [Atomic Type Reference](https://psalm.dev/docs/annotating_code/type_syntax/atomic_types/)
* Psalm: [Supported Annotations](https://psalm.dev/docs/annotating_code/supported_annotations/)
* Psalm: [Template Annotations](https://psalm.dev/docs/annotating_code/templated_annotations/)

### Changed

* Make continued expressions inside lists (arguments and arrays, etc.) have the same indent width as outside the list ([#703])
* (internal) Improved readability of test failures about indentation ([#707])
* `php-doc-annotation-tag` inherits `font-lock-doc-markup-face` if defined in Emacs 28 ([#711])
* Change `php-phpdoc-type-keywords` to `php-phpdoc-type-names` to avoid confusion ([#717])

### Fixed

Expand All @@ -26,6 +33,9 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
[#708]: https://github.com/emacs-php/php-mode/pull/708
[#710]: https://github.com/emacs-php/php-mode/pull/710
[#711]: https://github.com/emacs-php/php-mode/pull/711
[#715]: https://github.com/emacs-php/php-mode/pull/715
[#716]: https://github.com/emacs-php/php-mode/pull/716
[#717]: https://github.com/emacs-php/php-mode/pull/717

## [1.24.1] - 2022-10-08

Expand Down
17 changes: 12 additions & 5 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ for \\[find-tag] (which see)."
(message "Unknown function: %s" tagname))))

;; Font Lock
(defconst php-phpdoc-type-keywords
(defconst php-phpdoc-type-names
(list "string" "integer" "int" "boolean" "bool" "float"
"double" "object" "mixed" "array" "resource"
"void" "null" "false" "true" "self" "static"
Expand All @@ -1287,11 +1287,18 @@ for \\[find-tag] (which see)."
"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" "key-of" "value-of"))
"trait-string" "truthy-string" "key-of" "value-of")
"A list of type and pseudotype names that can be used in PHPDoc.")

(make-obsolete-variable 'php-phpdoc-type-keywords 'php-phpdoc-type-names "1.24.2")

(defconst php-phpdoc-type-tags
(list "package" "param" "property" "property-read" "property-write"
"return" "throws" "var" "self-out" "this-out" "param-out"))
"return" "throws" "var" "self-out" "this-out" "param-out"
"type" "extends" "require-extends" "implemtents" "require-implements"
"template" "template-covariant" "template-extends" "template-implements"
"assert" "assert-if-true" "assert-if-false" "if-this-is")
"A list of tags specifying type names.")

(defconst php-phpdoc-font-lock-doc-comments
`(("{@[-[:alpha:]]+\\s-*\\([^}]*\\)}" ; "{@foo ...}" markup.
Expand All @@ -1301,11 +1308,11 @@ 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-@" (rx (? (or "phpstan" "psalm") "-")) (regexp-opt php-phpdoc-type-tags) "\\s-+"
(,(concat "\\s-@" (rx (? (or "phan" "phpstan" "psalm") "-")) (regexp-opt php-phpdoc-type-tags) "\\s-+"
"\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+")
1 'php-string prepend nil)
(,(concat "\\(?:|\\|\\?\\|\\s-\\)\\("
(regexp-opt php-phpdoc-type-keywords 'words)
(regexp-opt php-phpdoc-type-names 'words)
"\\)")
1 font-lock-type-face prepend nil)
("https?://[^\n\t ]+"
Expand Down

0 comments on commit 865bc84

Please sign in to comment.