2828
2929(require 'lsp-dart-protocol )
3030(require 'lsp-dart-utils )
31+ (require 'lsp-dart-test-tree )
3132(require 'lsp-dart-dap )
3233
3334(defcustom lsp-dart-test-pop-to-buffer-on-run 'display-only
@@ -52,7 +53,6 @@ not become focused, otherwise the buffer is displayed and focused."
5253(defconst lsp-dart-test--skipped-icon " •" )
5354(defconst lsp-dart-test--error-icon " ✖" )
5455
55- (defvar lsp-dart-test--suites nil )
5656(defvar lsp-dart-test--tests nil )
5757(defvar lsp-dart-test--tests-count 0 )
5858(defvar lsp-dart-test--tests-passed 0 )
@@ -185,14 +185,6 @@ IGNORE-CASE is a optional arg to ignore the case sensitive on regex search."
185185 " Return the test from ID if exists."
186186 (alist-get id lsp-dart-test--tests))
187187
188- (defun lsp-dart-test--set-suite (path suite )
189- " Add SUITE with key PATH."
190- (setf (alist-get path lsp-dart-test--suites nil nil #'string= ) suite))
191-
192- (defun lsp-dart-test--get-suite (path )
193- " Return the suite from PATH if exists."
194- (alist-get path lsp-dart-test--suites nil nil #'string= ))
195-
196188(cl-defgeneric lsp-dart-test--handle-notification (type notification)
197189 " Extension point for handling custom events.
198190TYPE is the event to handle.
@@ -206,42 +198,49 @@ NOTIFICATION is the event notification.")
206198 " Handle start NOTIFICATION."
207199 (setq lsp-dart-test--tests nil )
208200 (setq lsp-dart-test--tests-count 0 )
209- (setq lsp-dart-test--tests-passed 0 ))
201+ (setq lsp-dart-test--tests-passed 0 )
202+ (lsp-dart-test-tree-clean))
210203
211204(cl-defmethod lsp-dart-test--handle-notification ((_event (eql testStart)) notification)
212205 " Handle testStart NOTIFICATION."
213- (-let (((&TestStartNotification :time :test (&Test :id :group-i-ds :name? )) notification))
206+ (-let (((&TestStartNotification :time :test (test &as &Test :id :group-i-ds :name? )) notification))
214207 (lsp-dart-test--set-test id (make-lsp-dart-test :id id
215208 :name name?
216209 :start-time time
217210 :group-ids group-i-ds))
218211 (unless (seq-empty-p group-i-ds)
219- (setq lsp-dart-test--tests-count (1+ lsp-dart-test--tests-count)))))
212+ (setq lsp-dart-test--tests-count (1+ lsp-dart-test--tests-count)))
213+ (lsp-dart-test-tree-set-test test 'running )))
220214
221215(cl-defmethod lsp-dart-test--handle-notification ((_event (eql allSuites)) _notification)
222216 " Handle allSuites NOTIFICATION." )
223217
224- (cl-defmethod lsp-dart-test--handle-notification ((_event (eql suite)) _notification)
225- " Handle suites NOTIFICATION." )
218+ (cl-defmethod lsp-dart-test--handle-notification ((_event (eql suite)) notification)
219+ " Handle suites NOTIFICATION."
220+ (-let (((&SuiteNotification :suite ) notification))
221+ (lsp-dart-test-tree-add-suite suite)))
226222
227- (cl-defmethod lsp-dart-test--handle-notification ((_event (eql group)) _notification)
228- " Handle group NOTIFICATION." )
223+ (cl-defmethod lsp-dart-test--handle-notification ((_event (eql group)) notification)
224+ " Handle group NOTIFICATION."
225+ (-let (((&GroupNotification :group ) notification))
226+ (lsp-dart-test-tree-set-group group)))
229227
230228(cl-defmethod lsp-dart-test--handle-notification ((_event (eql testDone)) notification)
231229 " Handle test done NOTIFICATION."
232- (-let (((&TestDoneNotification :test-id :result :time :hidden ) notification))
230+ (-let (((&TestDoneNotification :test-id :result :time :hidden :skipped ) notification))
233231 (unless hidden
234232 (when (string= result " success" )
235233 (setq lsp-dart-test--tests-passed (1+ lsp-dart-test--tests-passed)))
236234 (-when-let* ((test (lsp-dart-test--get-test test-id))
237- (time (propertize (format " (%s ms) "
238- (- time (lsp-dart-test-start-time test)))
239- 'font-lock-face 'font-lock-comment-face ))
235+ (formatted- time (propertize (format " (%s ms) "
236+ (- time (lsp-dart-test-start-time test)))
237+ 'font-lock-face 'font-lock-comment-face ))
240238 (text (propertize (concat (lsp-dart-test--get-icon notification)
241239 " "
242240 (lsp-dart-test-name test))
243241 'font-lock-face (lsp-dart-test--get-face notification))))
244- (lsp-dart-test--send-output " %s %s" text time)))))
242+ (lsp-dart-test--send-output " %s %s" text formatted-time)
243+ (lsp-dart-test-tree-mark-as-done test-id (- time (lsp-dart-test-start-time test)) result skipped)))))
245244
246245(cl-defmethod lsp-dart-test--handle-notification ((_event (eql done)) notification)
247246 " Handle done NOTIFICATION."
@@ -335,7 +334,9 @@ to run otherwise run all tests from file-name in TEST."
335334 (append (list test-file)))))
336335 (lsp-dart-test--run-process (lsp-dart-test--build-command) (lsp-dart-test--build-command-extra-args)))
337336 (lsp-dart-test--show-buffer)
338- (lsp-dart-test--send-output (concat " Running tests...\n " )))
337+ (lsp-dart-test--send-output " Running tests...\n " )
338+ (when lsp-dart-test-tree-on-run
339+ (lsp-dart-test-show-tree)))
339340
340341(defun lsp-dart-test--debug (test )
341342 " Debug Dart/Flutter TEST."
0 commit comments