Skip to content

Commit

Permalink
Fix highlighting of return types on different lines for abstract func…
Browse files Browse the repository at this point in the history
…tions

If a class name is specified as the return type of an abstract
function and positioned on another line than the `function` keyword,
the class name was not highlighted at all.

This commit highlights such class names as return types.
  • Loading branch information
fabacino committed Apr 23, 2018
1 parent 52ae90a commit 06da1d7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(defconst php-mode-version-number "1.19.0"
"PHP Mode version number.")

(defconst php-mode-modified "2018-04-08"
(defconst php-mode-modified "2018-04-23"
"PHP Mode build date.")

;; This file is free software; you can redistribute it and/or
Expand Down Expand Up @@ -1700,7 +1700,7 @@ a completion list."

;; Highlight return types in functions and methods.
("function.+:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face)
(")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\{" 1 font-lock-type-face)
(")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face)

;; Highlight class names used as nullable type hints
("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face)
Expand Down
6 changes: 6 additions & 0 deletions tests/type-hints.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public function getNullableObject(
): ?stdClass {
}

abstract public function getOtherObject(
): stdClass;

abstract public function getOtherNullableObject(
): ?stdClass;

public function getNsObject(
): \path\to\my\Object {
}
Expand Down
20 changes: 20 additions & 0 deletions tests/type-hints.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,26 @@
("(\n ): ?")
("stdClass" . font-lock-type-face)
(" {\n }\n\n ")
("abstract" . php-keyword)
(" ")
("public" . php-keyword)
(" ")
("function" . php-keyword)
(" ")
("getOtherObject" . php-function-name)
("(\n ): ")
("stdClass" . font-lock-type-face)
(";\n\n ")
("abstract" . php-keyword)
(" ")
("public" . php-keyword)
(" ")
("function" . php-keyword)
(" ")
("getOtherNullableObject" . php-function-name)
("(\n ): ?")
("stdClass" . font-lock-type-face)
(";\n\n ")
("public" . php-keyword)
(" ")
("function" . php-keyword)
Expand Down

0 comments on commit 06da1d7

Please sign in to comment.