Skip to content

Commit ae70f09

Browse files
authored
Merge pull request #23 from emacs-php/feature/offset-info
Add phpactor-history for debugging
2 parents 5e2fe46 + 0dc925b commit ae70f09

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

phpactor.el

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
;;; Code:
4242
(require 'json)
4343
(require 'php-project)
44+
(require 'ring)
4445

4546
;; Variables
4647
;;;###autoload
@@ -63,6 +64,8 @@
6364
(or (null v) (stringp v))))))
6465

6566
(defvar phpactor--debug nil)
67+
(defvar phpactor-history-size 100)
68+
(defvar phpactor-history-ring nil)
6669

6770
(defvar phpactor--buffer-name "*Phpactor*")
6871

@@ -71,6 +74,7 @@
7174
;; Special variables
7275
(defvar phpactor--execute-async nil)
7376

77+
;; Utility functions
7478
(defun phpactor-find-executable ()
7579
"Return Phpactor command or path to executable."
7680
(or phpactor-executable
@@ -89,10 +93,18 @@
8993
(cons (phpactor-find-executable)
9094
(cons sub-command args))
9195
" "))
96+
97+
(defun phpactor--add-history (name entry)
98+
"Add Phpactor history by `NAME' and `ENTRY'."
99+
(unless phpactor-history-ring
100+
(setq phpactor-history-ring (make-ring phpactor-history-size)))
101+
(ring-insert phpactor-history-ring (cons name entry)))
102+
92103

93104
;; Phpactor RPC
94105
(defun phpactor--rpc (action arguments)
95106
"Execute Phpactor `ACTION' subcommand with `ARGUMENTS'."
107+
(phpactor--add-history 'phpactor--rpc (list :action action :parameters arguments))
96108
(let ((json (json-encode (list :action action
97109
:parameters arguments)))
98110
(cmd (phpactor--make-command-string "rpc"
@@ -103,9 +115,6 @@
103115
(with-current-buffer (get-buffer-create "*Phpactor Input*")
104116
(erase-buffer)
105117
(insert json)
106-
(when phpactor--debug
107-
(message "Phpactor RPC input: %s" (buffer-substring-no-properties
108-
(point-min) (point-max))))
109118
(shell-command-on-region (point-min) (point-max) cmd output)
110119
(with-current-buffer output
111120
(goto-char (point-min))
@@ -249,8 +258,7 @@
249258
;; Dispatcher:
250259
(cl-defun phpactor-action-dispatch (&key action parameters)
251260
"Execite action by `NAME' and `PARAMETERS'."
252-
(when phpactor--debug
253-
(message "Phpactor dispatch %s %s" action parameters))
261+
(phpactor--add-history 'phpactor-action-dispatch (list :action action :parameters parameters))
254262
(let ((func (cdr-safe (assq (intern action) phpactor-action-table))))
255263
(if func
256264
(apply func parameters)

0 commit comments

Comments
 (0)