Skip to content

Commit d17e4ed

Browse files
authored
Merge pull request #499 from fabacino/bugfix/highlight-kwd-methods
Fix highlighting of static method calls
2 parents 2ac78cd + f961f24 commit d17e4ed

7 files changed

+76
-8
lines changed

php-mode-test.el

+5
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,11 @@ style from Drupal."
928928
"Test highlighting of type hints and return types."
929929
(with-php-mode-test ("type-hints.php" :faces t)))
930930

931+
(ert-deftest php-mode-test-static-method-calls ()
932+
"Test highlighting of static method calls which are named the same
933+
as a keyword."
934+
(with-php-mode-test ("static-method-calls.php" :faces t)))
935+
931936
(ert-deftest php-mode-debug-test ()
932937
"Test running php-mode-debug and php-mode-debug--buffer."
933938
(with-temp-buffer

php-mode.el

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(defconst php-mode-version-number "1.21.0"
1717
"PHP Mode version number.")
1818

19-
(defconst php-mode-modified "2019-02-28"
19+
(defconst php-mode-modified "2019-03-04"
2020
"PHP Mode build date.")
2121

2222
;; This file is free software; you can redistribute it and/or
@@ -1686,6 +1686,10 @@ a completion list."
16861686
;; Support the ::class constant in PHP5.6
16871687
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant))
16881688

1689+
;; Highlight static method calls as such. This is necessary for method
1690+
;; names which are identical to keywords to be highlighted correctly.
1691+
("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call)
1692+
16891693
;; While c-opt-cpp-* highlights the <?php opening tags, it is not
16901694
;; possible to make it highlight short open tags and closing tags
16911695
;; as well. So we force the correct face on all cases that

tests/constants.php.faces

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
(";\n")
4444
("SomeClass" . php-constant)
4545
("::" . php-paamayim-nekudotayim)
46-
("classIdentifier();\n\n")
46+
("classIdentifier" . php-static-method-call)
47+
("();\n\n")
4748
("__halt_compiler" . php-keyword)
4849
("();\n\n")
4950
("// " . font-lock-comment-delimiter-face)

tests/identifiers.php.faces

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
("the constant face. Just like c++-mode \"NS::Class::method()\"\n" . font-lock-comment-face)
3636
("ClassName" . php-constant)
3737
("::" . php-paamayim-nekudotayim)
38-
("method();\n")
38+
("method" . php-static-method-call)
39+
("();\n")
3940
("\\SpaceName\\ClassName" . php-constant)
4041
("::" . php-paamayim-nekudotayim)
41-
("method();\n")
42+
("method" . php-static-method-call)
43+
("();\n")
4244
("\\My_Class" . php-constant)
4345
("::" . php-paamayim-nekudotayim)
44-
("method();\n\n")
46+
("method" . php-static-method-call)
47+
("();\n\n")
4548
("__halt_compiler" . php-keyword)
4649
("();\n\n")
4750
("// " . font-lock-comment-delimiter-face)

tests/issue-201.php.faces

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
(";\n")
1919
("self" . php-keyword)
2020
("::" . php-paamayim-nekudotayim)
21-
("test();\n")
21+
("test" . php-static-method-call)
22+
("();\n")
2223
("static" . php-keyword)
2324
("::" . php-paamayim-nekudotayim)
24-
("test();\n")
25+
("test" . php-static-method-call)
26+
("();\n")
2527
("parent" . php-keyword)
2628
("::" . php-paamayim-nekudotayim)
27-
("test();\n"))
29+
("test" . php-static-method-call)
30+
("();\n"))

tests/static-method-calls.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
ClassName::method();
4+
\Project\Module\ClassName::method();
5+
\ClassName::method();
6+
7+
ClassName::new();
8+
\Project\Module\ClassName::new();
9+
\ClassName::new();
10+
11+
ClassName::clone();
12+
\Project\Module\ClassName::clone();
13+
\ClassName::clone();

tests/static-method-calls.php.faces

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("ClassName" . php-constant)
5+
("::" . php-paamayim-nekudotayim)
6+
("method" . php-static-method-call)
7+
("();\n")
8+
("\\Project\\Module\\ClassName" . php-constant)
9+
("::" . php-paamayim-nekudotayim)
10+
("method" . php-static-method-call)
11+
("();\n")
12+
("\\ClassName" . php-constant)
13+
("::" . php-paamayim-nekudotayim)
14+
("method" . php-static-method-call)
15+
("();\n\n")
16+
("ClassName" . php-constant)
17+
("::" . php-paamayim-nekudotayim)
18+
("new" . php-static-method-call)
19+
("();\n")
20+
("\\Project\\Module\\ClassName" . php-constant)
21+
("::" . php-paamayim-nekudotayim)
22+
("new" . php-static-method-call)
23+
("();\n")
24+
("\\ClassName" . php-constant)
25+
("::" . php-paamayim-nekudotayim)
26+
("new" . php-static-method-call)
27+
("();\n\n")
28+
("ClassName" . php-constant)
29+
("::" . php-paamayim-nekudotayim)
30+
("clone" . php-static-method-call)
31+
("();\n")
32+
("\\Project\\Module\\ClassName" . php-constant)
33+
("::" . php-paamayim-nekudotayim)
34+
("clone" . php-static-method-call)
35+
("();\n")
36+
("\\ClassName" . php-constant)
37+
("::" . php-paamayim-nekudotayim)
38+
("clone" . php-static-method-call)
39+
("();\n"))

0 commit comments

Comments
 (0)