branch: externals/phpinspect commit b6978105e5d27ddd3682918e856a7689092382f5 Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
Fix: Don't discard first char after opening brace of class block --- phpinspect-parser.el | 1 - test/test-buffer.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/phpinspect-parser.el b/phpinspect-parser.el index 728e546c2f..9e818e120a 100644 --- a/phpinspect-parser.el +++ b/phpinspect-parser.el @@ -716,7 +716,6 @@ static keywords with the same meaning as in a class block." (phpinspect-defhandler class-block (start-token max-point) "Handler for code blocks that cannot contain classes" ((regexp . "{")) - (forward-char (length start-token)) (let* ((complete-block nil) (continue-condition (lambda () (not (and (char-equal (char-after) ?}) diff --git a/test/test-buffer.el b/test/test-buffer.el index e5bfa16c10..eb2474c6e5 100644 --- a/test/test-buffer.el +++ b/test/test-buffer.el @@ -738,3 +738,47 @@ class Bar { (phpinspect-buffer-update-project-index buffer) (should (= 1 (length (phpi-typedef-get-methods class)))))))) + + +(ert-deftest phpinspect-buffer-parse-incrementally-class-block-scope () + (with-temp-buffer + (let* ((project (phpinspect--make-dummy-composer-project-with-code)) + (buffer (phpinspect-make-buffer :-project project :buffer (current-buffer)))) + + (insert "<?php class A { public function A() {} }") + + (setq-local phpinspect-current-buffer buffer) + (add-hook 'after-change-functions #'phpinspect-after-change-function) + (let ((expected `(:root + (:class + (:declaration + (:word "class") + (:word "A")) + (:block + (:public + (:function + (:declaration + (:word "function") + (:word "A") + (:list)) + (:block))))))) + (result (phpinspect-buffer-parse buffer 'no-interrupt))) + + (should result) + (pp result) + (should (equal expected result)) + + (goto-char 17) + (delete-backward-char 1) + (message (buffer-string)) + (setq result (phpinspect-buffer-parse buffer 'no-interrupt)) + (pp result) + (should result) + (should (equal expected result)) + + (backward-char) + (insert " ") + (message (buffer-string)) + (setq result (phpinspect-buffer-parse buffer 'no-interrupt)) + (should result) + (should (equal expected result))))))