Skip to content

Commit 7af6d26

Browse files
authored
Merge pull request #60 from emacs-lsp/tests-tree
Add tests tree
2 parents 21d1126 + de11ad2 commit 7af6d26

File tree

7 files changed

+413
-24
lines changed

7 files changed

+413
-24
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 1.17.0
4+
* Add test tree feature.
5+
* Add `lsp-dart-test-show-tree`
6+
7+
## 1.16.0
8+
* Improve tests backend and output.
9+
* Prepare for test tree feature.
10+
311
## 1.15.0
412
* Add `lsp-dart-enable-sdk-formatter` setting.
513
* Add `lsp-dart-line-length` setting.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ Running a test interactively:
8686

8787
![test](images/run-test.gif)
8888

89+
### Test tree
90+
91+
`lsp-dart-test-show-tree` - Open the test tree containing the latest ran tests.
92+
93+
![test-tree](images/test-tree.gif)
94+
95+
For more options, check the [settings section](#supported-settings).
96+
8997
### Flutter colors
9098

9199
Display the flutter colors on left fringe.
@@ -185,6 +193,10 @@ lsp-dart supports running Flutter and Dart commands as following:
185193
| `lsp-dart-flutter-fringe-colors` | Enable the Flutter colors on fringe. | `t` |
186194
| `lsp-dart-flutter-widget-guides` | Enable the Flutter widget guide lines from parent to child widgets | `t` |
187195
| `lsp-dart-test-pop-to-buffer-on-run` | Whether to pop to tests buffer on run, only display or do nothing. | `display-only` |
196+
| `lsp-dart-test-tree-on-run` | Whether to pop to tests tree buffer on run | `t` |
197+
| `lsp-dart-test-tree-position-params` | The test tree position params | Treemacs default |
198+
| `lsp-dart-test-tree-line-spacing` | The test tree line spacing between nodes | 4 |
199+
| `lsp-dart-test-tree-line-spacing` | The test tree line spacing between nodes | 4 |
188200
| `lsp-dart-main-code-lens` | Enable the `Run\|Debug` code lens on main methods. | `t` |
189201
| `lsp-dart-test-code-lens` | Enable the `Run\|Debug` code lens on tests. | `t` |
190202
| `lsp-dart-dap-extension-version` | The debugger extension version. | 3.10.1 |

images/test-tree.gif

31.8 KB
Loading

lsp-dart-code-lens.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
(defface lsp-dart-code-lens-separator
4545
'((t :height 0.3))
4646
"The face used for separate test code lens overlays."
47-
:group 'lsp-dart-test-support)
47+
:group 'lsp-dart)
4848

4949

5050
;; Internal

lsp-dart-protocol.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
(Suite (:id :platform :path) nil)
6262
(Test (:id :suiteID :groupIDs) (:name :line :column :url :root_line :root_column :root_url))
6363
(TestNotification (:type :time :test) nil)
64-
(Group (:testCount) (:parentID))
64+
(GroupMetadata (:skip) nil)
65+
(Group (:id :suiteID :testCount) (:parentID :name :url :line :column :metadata))
6566
(GroupNotification (:type :time :group) nil)
6667
(TestStartNotification (:type :time :test) nil)
6768
(TestDoneNotification (:type :time :testID :result :skipped :hidden) nil)

lsp-dart-test-support.el

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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.
198190
TYPE 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

Comments
 (0)