Skip to content

Commit 8d20488

Browse files
committed
Refactor test tree to listen to hooks
1 parent 231d120 commit 8d20488

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

lsp-dart-test-support.el

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,37 +120,32 @@ NOTIFICATION is the event notification.")
120120
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql start)) notification)
121121
"Handle start NOTIFICATION."
122122
(setq lsp-dart-test--tests nil)
123-
(run-hook-with-args 'lsp-dart-test-all-start-notification-hook notification)
124-
(lsp-dart-test-tree-clean))
123+
(run-hook-with-args 'lsp-dart-test-all-start-notification-hook notification))
125124

126125
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql testStart)) notification)
127126
"Handle testStart NOTIFICATION."
128-
(-let (((&TestStartNotification :time :test (test &as &Test :id :group-i-ds :name?)) notification))
127+
(-let (((&TestStartNotification :time :test (&Test :id :group-i-ds :name?)) notification))
129128
(lsp-dart-test--set-test id (make-lsp-dart-test :id id
130129
:name name?
131130
:start-time time
132131
:group-ids group-i-ds))
133-
(run-hook-with-args 'lsp-dart-test-start-notification-hook notification)
134-
(lsp-dart-test-tree-set-test test 'running)))
132+
(run-hook-with-args 'lsp-dart-test-start-notification-hook notification)))
135133

136134
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql allSuites)) _notification)
137135
"Handle allSuites NOTIFICATION.")
138136

139137
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql suite)) notification)
140-
"Handle suites NOTIFICATION."
141-
(-let (((&SuiteNotification :suite) notification))
142-
(lsp-dart-test-tree-add-suite suite)))
138+
"Handle suite NOTIFICATION."
139+
(run-hook-with-args 'lsp-dart-test-suite-notification-hook notification))
143140

144141
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql group)) notification)
145142
"Handle group NOTIFICATION."
146-
(-let (((&GroupNotification :group) notification))
147-
(lsp-dart-test-tree-set-group group)))
143+
(run-hook-with-args 'lsp-dart-test-group-notification-hook notification))
148144

149145
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql testDone)) notification)
150146
"Handle test done NOTIFICATION."
151-
(-let (((&TestDoneNotification :test-id :result :time :skipped) notification))
147+
(-let (((&TestDoneNotification :test-id) notification))
152148
(when-let (test (lsp-dart-test--get-test test-id))
153-
(lsp-dart-test-tree-mark-as-done test-id (- time (lsp-dart-test-start-time test)) result skipped)
154149
(run-hook-with-args 'lsp-dart-test-done-notification-hook
155150
notification
156151
(lsp-dart-test-name test)
@@ -220,9 +215,7 @@ to run otherwise run all tests from file-name in TEST."
220215
(lsp-dart-assoc-if test-arg test-arg)
221216
(append (list test-file)))))
222217
(lsp-dart-test--run-process (lsp-dart-test--build-command) (lsp-dart-test--build-command-extra-args)))
223-
(run-hooks 'lsp-dart-test-run-started-hook)
224-
(when lsp-dart-test-tree-on-run
225-
(lsp-dart-test-show-tree)))
218+
(run-hooks 'lsp-dart-test-run-started-hook))
226219

227220
(defun lsp-dart-test--debug (test)
228221
"Debug Dart/Flutter TEST."

lsp-dart-test-tree.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,30 @@ POSITION is the test start position."
291291
t
292292
lsp-dart-test-tree--buffer-name)))
293293

294+
(defun lsp-dart-test-tree--handle-run-started ()
295+
"Handle run started notification."
296+
(when lsp-dart-test-tree-on-run
297+
(lsp-dart-test-show-tree)))
298+
299+
(lsp-defun lsp-dart-test-tree--handle-suite ((&SuiteNotification :suite))
300+
"Handle suite notification."
301+
(lsp-dart-test-tree-add-suite suite))
302+
303+
(defun lsp-dart-test-tree--handle-all-start (_notification)
304+
"Handle all start notification."
305+
(lsp-dart-test-tree-clean))
306+
307+
(lsp-defun lsp-dart-test-tree--handle-group ((&GroupNotification :group))
308+
(lsp-dart-test-tree-set-group group))
309+
310+
(lsp-defun lsp-dart-test-tree--handle-start ((&TestStartNotification :test))
311+
"Handle test start notification."
312+
(lsp-dart-test-tree-set-test test 'running))
313+
314+
(lsp-defun lsp-dart-test-tree--handle-done ((&TestDoneNotification :test-id :result :time :skipped) _test-name test-start-time)
315+
"Handle test done notification."
316+
(lsp-dart-test-tree-mark-as-done test-id (- time test-start-time) result skipped))
317+
294318

295319
;;; Public
296320

@@ -362,6 +386,12 @@ POSITION is the test start position."
362386
(setq-local line-spacing lsp-dart-test-tree-line-spacing))
363387
(display-buffer-in-side-window tree-buffer lsp-dart-test-tree-position-params)))
364388

389+
(add-hook 'lsp-dart-test-run-started-hook #'lsp-dart-test-tree--handle-run-started)
390+
(add-hook 'lsp-dart-test-suite-notification-hook #'lsp-dart-test-tree--handle-suite)
391+
(add-hook 'lsp-dart-test-all-start-notification-hook #'lsp-dart-test-tree--handle-all-start)
392+
(add-hook 'lsp-dart-test-group-notification-hook #'lsp-dart-test-tree--handle-group)
393+
(add-hook 'lsp-dart-test-start-notification-hook #'lsp-dart-test-tree--handle-start)
394+
(add-hook 'lsp-dart-test-done-notification-hook #'lsp-dart-test-tree--handle-done)
365395

366396
(provide 'lsp-dart-test-tree)
367397
;;; lsp-dart-test-tree.el ends here

0 commit comments

Comments
 (0)