Skip to content

Commit 0968038

Browse files
authored
Actually implement the documented dwim behaviour (#373)
dap-java--run-unit-test-command (and other functions) document that if no test method exists at point they will fall back to running the class tests. In actuality they signal a user-error if no method exists at point. This commit implements the documented behaviour (which seems more useful than updating the documentation to match the actual behaviour). Fixes #371
1 parent ce03cb6 commit 0968038

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

dap-java.el

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If the port is taken, DAP will try the next port."
108108
(lsp-interface
109109
(java:MainClass (:mainClass :projectName))))
110110

111-
(defun dap-java-test-class ()
111+
(defun dap-java-test-class (&optional no-signal?)
112112
"Get class FDQN."
113113
(-if-let* ((symbols (lsp--get-document-symbols))
114114
(package-name (-some->> symbols
@@ -118,9 +118,10 @@ If the port is taken, DAP will try the next port."
118118
(--first (= (lsp:document-symbol-kind it) lsp/symbol-kind-class))
119119
lsp:document-symbol-name)))
120120
(concat package-name "." class-name)
121-
(user-error "No class found")))
121+
(unless no-signal?
122+
(user-error "No class found"))))
122123

123-
(defun dap-java-test-method-at-point ()
124+
(defun dap-java-test-method-at-point (&optional no-signal?)
124125
"Get method at point."
125126
(-let* ((symbols (lsp--get-document-symbols))
126127
(package-name (-some->> symbols
@@ -137,7 +138,8 @@ If the port is taken, DAP will try the next port."
137138
(lsp-region-text selection-range)))))
138139
children?))))
139140
(cl-first))
140-
(user-error "No method at point"))))
141+
(unless no-signal?
142+
(user-error "No method at point")))))
141143

142144
(defun dap-java--select-main-class ()
143145
"Select main class from the current workspace."
@@ -245,11 +247,12 @@ initiate `compile' and attach to the process."
245247
(interactive (list (dap-java--populate-default-args nil)))
246248
(dap-start-debugging debug-args))
247249

248-
(defun dap-java--run-unit-test-command (runner run-method?)
250+
(defun dap-java--run-unit-test-command (runner dwim?)
249251
"Run debug test with the following arguments.
250-
RUNNER is the test executor. RUN-METHOD? when t it will try to run the
251-
surrounding method. Otherwise it will run the surronding test."
252-
(-let* ((to-run (if run-method?
252+
RUNNER is the test executor. DWIM? when t it will try to run the
253+
surrounding method. Otherwise it will run the surrounding test."
254+
(-let* ((run-method? (and dwim? (dap-java-test-method-at-point t)))
255+
(to-run (if run-method?
253256
(dap-java-test-method-at-point)
254257
(dap-java-test-class)))
255258
(test-class-name (cl-first (s-split "#" to-run)))

0 commit comments

Comments
 (0)