Skip to content

Fix highlighting of static method calls #499

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

Merged
merged 1 commit into from
Apr 1, 2019
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
5 changes: 5 additions & 0 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,11 @@ style from Drupal."
"Test highlighting of type hints and return types."
(with-php-mode-test ("type-hints.php" :faces t)))

(ert-deftest php-mode-test-static-method-calls ()
"Test highlighting of static method calls which are named the same
as a keyword."
(with-php-mode-test ("static-method-calls.php" :faces t)))

(ert-deftest php-mode-debug-test ()
"Test running php-mode-debug and php-mode-debug--buffer."
(with-temp-buffer
Expand Down
6 changes: 5 additions & 1 deletion php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(defconst php-mode-version-number "1.21.0"
"PHP Mode version number.")

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

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

;; Highlight static method calls as such. This is necessary for method
;; names which are identical to keywords to be highlighted correctly.
("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call)

;; While c-opt-cpp-* highlights the <?php opening tags, it is not
;; possible to make it highlight short open tags and closing tags
;; as well. So we force the correct face on all cases that
Expand Down
3 changes: 2 additions & 1 deletion tests/constants.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
(";\n")
("SomeClass" . php-constant)
("::" . php-paamayim-nekudotayim)
("classIdentifier();\n\n")
("classIdentifier" . php-static-method-call)
("();\n\n")
("__halt_compiler" . php-keyword)
("();\n\n")
("// " . font-lock-comment-delimiter-face)
Expand Down
9 changes: 6 additions & 3 deletions tests/identifiers.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
("the constant face. Just like c++-mode \"NS::Class::method()\"\n" . font-lock-comment-face)
("ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method();\n")
("method" . php-static-method-call)
("();\n")
("\\SpaceName\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method();\n")
("method" . php-static-method-call)
("();\n")
("\\My_Class" . php-constant)
("::" . php-paamayim-nekudotayim)
("method();\n\n")
("method" . php-static-method-call)
("();\n\n")
("__halt_compiler" . php-keyword)
("();\n\n")
("// " . font-lock-comment-delimiter-face)
Expand Down
9 changes: 6 additions & 3 deletions tests/issue-201.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
(";\n")
("self" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test();\n")
("test" . php-static-method-call)
("();\n")
("static" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test();\n")
("test" . php-static-method-call)
("();\n")
("parent" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test();\n"))
("test" . php-static-method-call)
("();\n"))
13 changes: 13 additions & 0 deletions tests/static-method-calls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

ClassName::method();
\Project\Module\ClassName::method();
\ClassName::method();

ClassName::new();
\Project\Module\ClassName::new();
\ClassName::new();

ClassName::clone();
\Project\Module\ClassName::clone();
\ClassName::clone();
39 changes: 39 additions & 0 deletions tests/static-method-calls.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . php-php-tag)
("\n\n")
("ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("();\n")
("\\Project\\Module\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("();\n")
("\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("();\n\n")
("ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("new" . php-static-method-call)
("();\n")
("\\Project\\Module\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("new" . php-static-method-call)
("();\n")
("\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("new" . php-static-method-call)
("();\n\n")
("ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("clone" . php-static-method-call)
("();\n")
("\\Project\\Module\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("clone" . php-static-method-call)
("();\n")
("\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("clone" . php-static-method-call)
("();\n"))