Skip to content

Commit 4b1d05e

Browse files
committed
Rewrite run/debug code lens handling to use a minor mode just like lsp-java
1 parent b66b5f5 commit 4b1d05e

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

clients/lsp-kotlin.el

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ to Kotlin."
125125

126126

127127
;; Debug and running
128+
(declare-function dap-debug "ext:dap-mode" (template) t)
129+
128130
(defun lsp-kotlin-run-main (main-class project-root debug?)
129131
(require 'dap-kotlin)
130132
(dap-debug (list :type "kotlin"
@@ -137,19 +139,20 @@ to Kotlin."
137139
(when lsp-kotlin-debug-adapter-enabled
138140
(lsp-request-async
139141
"kotlin/mainClass"
140-
(list :uri (vector (lsp--buffer-uri)))
142+
(list :uri (lsp--buffer-uri))
141143
(lambda (mainInfo)
142-
;; range became nil when using -let, so using lsp-get for it below instead
143-
(-let [(&hash :mainClass main-class :projectRoot project-root) mainInfo]
144+
(let ((main-class (lsp-get mainInfo :mainClass))
145+
(project-root (lsp-get mainInfo :projectRoot))
146+
(range (lsp-get mainInfo :range)))
144147
(funcall callback
145-
(list (lsp-make-code-lens :range (lsp-get mainInfo :range)
148+
(list (lsp-make-code-lens :range range
146149
:command
147150
(lsp-make-command
148151
:title "Run"
149152
:command (lambda ()
150153
(interactive)
151154
(lsp-kotlin-run-main main-class project-root nil))))
152-
(lsp-make-code-lens :range (lsp-get mainInfo :range)
155+
(lsp-make-code-lens :range range
153156
:command
154157
(lsp-make-command
155158
:title "Debug"
@@ -159,6 +162,24 @@ to Kotlin."
159162
lsp--cur-version)))
160163
:mode 'tick)))
161164

165+
(defvar lsp-lens-backends)
166+
(declare-function lsp-lens-refresh "lsp-lens" (buffer-modified? &optional buffer))
167+
168+
(define-minor-mode lsp-kotlin-lens-mode
169+
"Toggle run/debug overlays."
170+
:group 'lsp-kotlin
171+
:global nil
172+
:init-value nil
173+
:lighter nil
174+
(cond
175+
(lsp-kotlin-lens-mode
176+
(require 'lsp-lens)
177+
;; set lens backends so they are available is lsp-lens-mode is activated
178+
;; backend does not support lenses, and block our other ones from showing. When backend support lenses again, we can use cl-pushnew to add it to lsp-lens-backends instead of overwriting
179+
(setq-local lsp-lens-backends (list #'lsp-kotlin-lens-backend))
180+
(lsp-lens-refresh t))
181+
(t (setq-local lsp-lens-backends (delete #'lsp-kotlin-lens-backend lsp-lens-backends)))))
182+
162183

163184
(lsp-dependency
164185
'kotlin-language-server
@@ -184,11 +205,7 @@ to Kotlin."
184205
(with-lsp-workspace workspace
185206
(lsp--set-configuration (lsp-configuration-section "kotlin"))))
186207
:download-server-fn (lambda (_client callback error-callback _update?)
187-
(lsp-package-ensure 'kotlin-language-server callback error-callback))
188-
:after-open-fn (lambda ()
189-
;; set lens backends so they are available is lsp-lens-mode is activated
190-
;; backend does not support lenses, and block our other ones from showing. When backend support lenses again, we can use cl-pushnew to add it to lsp-lens-backends instead of overwriting
191-
(setq-local lsp-lens-backends (list #'lsp-kotlin-lens-backend)))))
208+
(lsp-package-ensure 'kotlin-language-server callback error-callback))))
192209

193210
(lsp-consistency-check lsp-kotlin)
194211

0 commit comments

Comments
 (0)