2525(defvar hie-process nil
2626 " Variable holding current Haskell IDE Engine process" )
2727
28- (defvar hie-buffer nil
29- " Variable holding current Haskell IDE Engine buffer" )
28+ (defvar hie-log-buffer nil
29+ " Variable holding current Haskell IDE Engine log buffer" )
30+
31+ (defvar hie-process-buffer nil
32+ " Variable holding current Haskell IDE Engine process buffer" )
3033
3134(defvar hie-process-handle-message nil
3235 " A function to handle json object." )
4144
4245(defun hie-process-filter (process input )
4346 (let ((prev-buffer (current-buffer )))
44- (with-current-buffer hie-buffer
45-
47+ (with-current-buffer hie-process-buffer
4648 (let ((point (point )))
4749 (insert input)
4850 (save-excursion
4951 (goto-char point)
5052 (when (re-search-forward " \^ b" nil t )
51- (let* ((end-of-current-json-object (match-beginning 0 ))
52- (after-stx-marker (match-end 0 ))
53+ (let* ((after-stx-marker (match-end 0 ))
54+ (input-text (buffer-substring-no-properties (point-min ) (match-beginning 0 )))
55+ (handle-error (lambda ()
56+ (when hie-process-handle-invalid-input
57+ (hie-log " <-parse-error %s" input-text)
58+ (funcall hie-process-handle-invalid-input input-text))))
5359 (json-array-type 'list ))
5460 (goto-char (point-min ))
5561 (condition-case nil
5662 (let ((json (json-read )))
5763 (when hie-process-handle-message
5864 (with-current-buffer prev-buffer
65+ (hie-log " <- %s" input-text)
5966 (funcall hie-process-handle-message json))))
6067 ; ; json-readtable-error is when there is an unexpected character in input
61- (json-readtable-error
62- (when hie-process-handle-invalid-input
63- (funcall hie-process-handle-invalid-input
64- (buffer-substring-no-properties (point-min ) end-of-current-json-object))))
68+ (json-readtable-error (funcall handle-error))
6569 ; ; json-unknown-keyword when unrecognized keyword is parsed
66- (json-unknown-keyword
67- (when hie-process-handle-invalid-input
68- (funcall hie-process-handle-invalid-input
69- (buffer-substring-no-properties (point-min ) end-of-current-json-object))))
70- (end-of-file
71- (when hie-process-handle-invalid-input
72- (funcall hie-process-handle-invalid-input
73- (buffer-substring-no-properties (point-min ) end-of-current-json-object)))))
70+ (json-unknown-keyword (funcall handle-error))
71+ (end-of-file (funcall handle-error)))
7472 (delete-region (point-min ) after-stx-marker))))))))
7573
7674(defun hie-start-process ()
@@ -81,12 +79,14 @@ running this function does nothing."
8179 (interactive )
8280
8381 (unless (hie-process-live-p)
84- (setq hie-buffer
85- (get-buffer-create " *hie*" ))
82+ (setq hie-log-buffer
83+ (get-buffer-create " *hie-log*" ))
84+ (setq hie-process-buffer
85+ (get-buffer-create " *hie-process*" ))
8686 (setq hie-process
8787 (apply #'start-process
8888 " Haskell IDE Engine"
89- hie-buffer
89+ hie-process- buffer
9090 hie-command
9191 hie-command-args))
9292 (set-process-query-on-exit-flag hie-process nil )
@@ -104,8 +104,14 @@ running this function does nothing."
104104 (when (hie-process-live-p)
105105 (kill-process hie-process)
106106 (setq hie-process nil )
107- (kill-buffer hie-buffer)
108- (setq hie-buffer nil )))
107+ (kill-buffer hie-process-buffer)
108+ (setq hie-process-buffer nil )))
109+
110+ (defun hie-log (&rest args )
111+ (with-current-buffer hie-log-buffer
112+ (goto-char (point-max ))
113+ (insert (apply #'format args)
114+ " \n " )))
109115
110116(defun hie-post-message (json )
111117 " Post a message to Haskell IDE Engine.
@@ -118,7 +124,7 @@ by `hie-handle-message'."
118124 ; ; accepts missing fields and default to empty when possible.
119125 (let ((prepared-json (hie-prepare-json json)))
120126 (run-hook-with-args 'hie-post-message-hook prepared-json)
121-
127+ (hie-log " -> %s " prepared-json)
122128 (process-send-string hie-process prepared-json)
123129 ; ; send \STX marker and flush buffers
124130 (process-send-string hie-process " \^ b\n " )))
0 commit comments