Skip to content

Commit

Permalink
Indentation handles magic class constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohansson committed Aug 9, 2019
1 parent dae1126 commit aed4e0d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions phps-mode-functions.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
(in-return nil)
(in-return-curly-bracket-level nil)
(in-return-level 0)
(previous-token nil)
(token nil)
(token-start nil)
(token-end nil)
Expand Down Expand Up @@ -236,6 +237,7 @@
(next-token-end-line-number nil))

(when token
;; NOTE We use a incremental-line-number calculation because `line-at-pos' takes a lot of time
(setq incremental-line-number (+ incremental-line-number (phps-mode-functions--get-lines-in-buffer token-end next-token-start))))

;; Handle the pseudo-token for last-line
Expand All @@ -244,12 +246,17 @@
(setq next-token-start-line-number (1+ token-start-line-number))
(setq next-token-end-line-number (1+ token-end-line-number)))
(setq next-token-start-line-number incremental-line-number)

;; NOTE We use a incremental-line-number calculation because `line-at-pos' takes a lot of time
(setq incremental-line-number (+ incremental-line-number (phps-mode-functions--get-lines-in-buffer next-token-start next-token-end)))
(setq next-token-end-line-number incremental-line-number)
(when phps-mode-functions-verbose
(message "Token '%s' pos: %s-%s lines: %s-%s" next-token next-token-start next-token-end next-token-start-line-number next-token-end-line-number)))

;; Token logic - we have one token look-ahead at this point
;; Token logic - we have one-two token look-ahead at this point
;; `token' is previous token
;; `next-token' is current token
;; `previous-token' is maybe two tokens back
(when token


Expand Down Expand Up @@ -388,7 +395,11 @@
)
(when first-token-on-line
(setq in-class-declaration-level 1)))
(when (equal token 'T_CLASS)

;; If ::class is used as a magical class constant it should not be considered start of a class declaration
(when (and (equal token 'T_CLASS)
(or (not previous-token)
(not (equal previous-token 'T_PAAMAYIM_NEKUDOTAYIM))))
(setq in-class-declaration t)
(setq in-class-declaration-level 1)
(setq class-declaration-started-this-line t)))
Expand Down Expand Up @@ -862,6 +873,7 @@
(setq tuning-level 0))))

;; Update current token
(setq previous-token token)
(setq token next-token)
(setq token-start next-token-start)
(setq token-end next-token-end)
Expand Down Expand Up @@ -941,6 +953,7 @@

)))))))

;; TODO Consider how imenu-index should be affected by this
(defun phps-mode-functions-after-change (start _stop _length)
"Track buffer change from START to STOP with length LENGTH."
(when (and (string= major-mode "phps-mode")
Expand Down
1 change: 1 addition & 0 deletions phps-mode-lexer.el
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@
(push token new-tokens))))))
new-tokens))

;; TODO Consider how imenu-index should be affected by this
(defun phps-mode-lexer-run-incremental ()
"Run incremental lexer based on `(phps-mode-functions-get-buffer-changes-start)'."
;; (message "Running incremental lexer")
Expand Down
5 changes: 5 additions & 0 deletions phps-mode-test-functions.el
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@
"Assignment with three-dimensional array with double arrow assignment"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))

(phps-mode-test-with-buffer
"<?php\nif ($myCondition) {\n $myObject->myMethod(myClass::class)\n ->myMethod2($myArgument2);\n }"
"Imenu object-oriented file with bracket-less namespace with multiple levels, class that extends and implements and functions with optional arguments"
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))

)

(defun phps-mode-test-functions-get-lines-indent-psr-2 ()
Expand Down

0 comments on commit aed4e0d

Please sign in to comment.