25
25
(defvar hie-process nil
26
26
" Variable holding current Haskell IDE Engine process" )
27
27
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" )
30
33
31
34
(defvar hie-process-handle-message nil
32
35
" A function to handle json object." )
41
44
42
45
(defun hie-process-filter (process input )
43
46
(let ((prev-buffer (current-buffer )))
44
- (with-current-buffer hie-buffer
45
-
47
+ (with-current-buffer hie-process-buffer
46
48
(let ((point (point )))
47
49
(insert input)
48
50
(save-excursion
49
51
(goto-char point)
50
52
(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))))
53
59
(json-array-type 'list ))
54
60
(goto-char (point-min ))
55
61
(condition-case nil
56
62
(let ((json (json-read )))
57
63
(when hie-process-handle-message
58
64
(with-current-buffer prev-buffer
65
+ (hie-log " <- %s" input-text)
59
66
(funcall hie-process-handle-message json))))
60
67
; ; 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))
65
69
; ; 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)))
74
72
(delete-region (point-min ) after-stx-marker))))))))
75
73
76
74
(defun hie-start-process ()
@@ -81,12 +79,14 @@ running this function does nothing."
81
79
(interactive )
82
80
83
81
(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*" ))
86
86
(setq hie-process
87
87
(apply #'start-process
88
88
" Haskell IDE Engine"
89
- hie-buffer
89
+ hie-process- buffer
90
90
hie-command
91
91
hie-command-args))
92
92
(set-process-query-on-exit-flag hie-process nil )
@@ -104,8 +104,14 @@ running this function does nothing."
104
104
(when (hie-process-live-p)
105
105
(kill-process hie-process)
106
106
(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 " )))
109
115
110
116
(defun hie-post-message (json )
111
117
" Post a message to Haskell IDE Engine.
@@ -118,7 +124,7 @@ by `hie-handle-message'."
118
124
; ; accepts missing fields and default to empty when possible.
119
125
(let ((prepared-json (hie-prepare-json json)))
120
126
(run-hook-with-args 'hie-post-message-hook prepared-json)
121
-
127
+ (hie-log " -> %s " prepared-json)
122
128
(process-send-string hie-process prepared-json)
123
129
; ; send \STX marker and flush buffers
124
130
(process-send-string hie-process " \^ b\n " )))
0 commit comments