Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Support ~labelDetails~ of Lsp Specification 3.17
* Add Gleam support
* Drop deprecated rust-analyzer variable lsp-rust-analyzer-import-merge-behaviour
* Added run and debug code lenses to ~lsp-kotlin~
** Release 8.0.0
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.
* Set ~lsp-clients-angular-language-server-command~ after the first connection to speed up subsequent connections.
Expand Down
59 changes: 59 additions & 0 deletions clients/lsp-kotlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
;;; Code:

(require 'lsp-mode)
(require 'cl-lib)

(defgroup lsp-kotlin nil
"LSP support for Kotlin, using KotlinLanguageServer."
Expand Down Expand Up @@ -122,6 +123,64 @@ to Kotlin."
"kotlin-language-server"))
"The path to store the language server at if necessary.")


;; Debug and running
(declare-function dap-debug "ext:dap-mode" (template) t)

(defun lsp-kotlin-run-main (main-class project-root debug?)
(require 'dap-kotlin)
(dap-debug (list :type "kotlin"
:request "launch"
:mainClass main-class
:projectRoot project-root
:noDebug (not debug?))))

(defun lsp-kotlin-lens-backend (_modified? callback)
(when lsp-kotlin-debug-adapter-enabled
(lsp-request-async
"kotlin/mainClass"
(list :uri (lsp--buffer-uri))
(lambda (mainInfo)
(let ((main-class (lsp-get mainInfo :mainClass))
(project-root (lsp-get mainInfo :projectRoot))
(range (lsp-get mainInfo :range)))
(funcall callback
(list (lsp-make-code-lens :range range
:command
(lsp-make-command
:title "Run"
:command (lambda ()
(interactive)
(lsp-kotlin-run-main main-class project-root nil))))
(lsp-make-code-lens :range range
:command
(lsp-make-command
:title "Debug"
:command (lambda ()
(interactive)
(lsp-kotlin-run-main main-class project-root t)))))
lsp--cur-version)))
:mode 'tick)))

(defvar lsp-lens-backends)
(declare-function lsp-lens-refresh "lsp-lens" (buffer-modified? &optional buffer))

(define-minor-mode lsp-kotlin-lens-mode
"Toggle run/debug overlays."
:group 'lsp-kotlin
:global nil
:init-value nil
:lighter nil
(cond
(lsp-kotlin-lens-mode
(require 'lsp-lens)
;; set lens backends so they are available is lsp-lens-mode is activated
;; 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
(setq-local lsp-lens-backends (list #'lsp-kotlin-lens-backend))
(lsp-lens-refresh t))
(t (setq-local lsp-lens-backends (delete #'lsp-kotlin-lens-backend lsp-lens-backends)))))


(lsp-dependency
'kotlin-language-server
`(:system ,lsp-clients-kotlin-server-executable)
Expand Down