24
24
25
25
; ;; Code:
26
26
27
+ (require 'cl-lib )
27
28
(require 'lsp-mode )
28
29
29
30
(require 'lsp-dart-project )
33
34
34
35
; ;; Internal
35
36
37
+ (cl-defstruct lsp-dart-test
38
+ (file-name nil )
39
+ (names nil )
40
+ (position nil )
41
+ (kind nil ))
42
+
36
43
(defun lsp-dart-test-support--test-kind-p (kind )
37
44
" Return non-nil if KIND is a test type."
38
45
(or (string= kind " UNIT_TEST_TEST" )
@@ -92,20 +99,25 @@ otherwise the dart command."
92
99
escaped-str nil t )))
93
100
escaped-str))
94
101
95
- (defun lsp-dart-test-support-run (buffer &optional names kind )
102
+ (defun lsp-dart-test-support-run (test )
96
103
" Run Dart/Flutter test command in a compilation buffer for BUFFER file.
97
- If NAMES is non nil, it will run only for KIND the test joining the name
98
- from NAMES."
104
+ If TEST is non nil, it will run only this test."
99
105
(interactive )
100
106
(lsp-dart-test-support--from-project-root
101
- (let* ((test-file (file-relative-name (buffer-file-name buffer)
107
+ (let* ((file-name (lsp-dart-test-file-name test))
108
+ (buffer (get-file-buffer file-name))
109
+ (names (lsp-dart-test-names test))
110
+ (kind (lsp-dart-test-kind test))
111
+ (test-file (file-relative-name file-name
102
112
(lsp-dart-project-get-root)))
103
113
(test-name (lsp-dart-test-support--build-test-name names))
104
114
(group-kind? (string= kind " UNIT_TEST_GROUP" ))
105
115
(test-arg (when test-name
106
116
(concat " --name '^"
107
117
(lsp-dart-test-support--escape-test-name test-name)
108
118
(if group-kind? " '" " $'" )))))
119
+ (when names
120
+ (lsp-workspace-set-metadata " last-ran-test" test))
109
121
(compilation-start (format " %s test %s %s "
110
122
(lsp-dart-test-support--build-command buffer)
111
123
(or test-arg " " )
@@ -122,10 +134,13 @@ TEST-RANGE is the test method range."
122
134
(beg-line (progn (goto-char beg)
123
135
(line-beginning-position )))
124
136
(spaces (make-string beg-position ?\s ))
125
- (overlay (make-overlay beg-line end buffer)))
137
+ (overlay (make-overlay beg-line end buffer))
138
+ (test (make-lsp-dart-test :file-name (buffer-file-name buffer)
139
+ :names names
140
+ :position beg
141
+ :kind kind)))
126
142
(overlay-put overlay 'lsp-dart-test-code-lens t )
127
- (overlay-put overlay 'lsp-dart-test-names names)
128
- (overlay-put overlay 'lsp-dart-test-kind kind)
143
+ (overlay-put overlay 'lsp-dart-test test)
129
144
(overlay-put overlay 'lsp-dart-test-overlay-test-range (lsp--range-to-region test-range))
130
145
(overlay-put overlay 'before-string
131
146
(concat spaces
@@ -135,7 +150,7 @@ TEST-RANGE is the test method range."
135
150
'local-map (-doto (make-sparse-keymap )
136
151
(define-key [mouse-1] (lambda ()
137
152
(interactive )
138
- (lsp-dart-test-support-run buffer names kind ))))
153
+ (lsp-dart-test-support-run test ))))
139
154
'font-lock-face 'lsp-lens-face )))))
140
155
141
156
(defun lsp-dart-test-support--add-code-lens (buffer items &optional names )
@@ -168,6 +183,28 @@ PARAMS is the notification data from outline."
168
183
" Return non-nil if FILE-NAME is a dart test files."
169
184
(string-match " _test.dart" file-name))
170
185
186
+ (defun lsp-dart-test-support-run-last-test ()
187
+ " Visit the last ran test going to the test definition."
188
+ (if-let ((test (lsp-workspace-get-metadata " last-ran-test" )))
189
+ (lsp-dart-test-support-run test)
190
+ (lsp-dart-project-log " No last test found." )))
191
+
192
+ (defun lsp-dart-test-support-visit-last-test ()
193
+ " Visit the last ran test going to the test definition."
194
+ (-if-let* ((test (lsp-workspace-get-metadata " last-ran-test" ))
195
+ (file-name (lsp-dart-test-file-name test))
196
+ (buffer (or (get-file-buffer file-name)
197
+ (find-file file-name)))
198
+ (position (lsp-dart-test-position test)))
199
+ (if-let ((window (get-buffer-window buffer 'visible )))
200
+ (progn
201
+ (select-window window)
202
+ (goto-char position))
203
+ (with-current-buffer buffer
204
+ (switch-to-buffer buffer nil t )
205
+ (goto-char position)))
206
+ (lsp-dart-project-log " No last test found." )))
207
+
171
208
172
209
(provide 'lsp-dart-test-support )
173
210
; ;; lsp-dart-test-support.el ends here
0 commit comments