From 72eaf530cf08e8a2859bbd5b02f46fc03307ee8c Mon Sep 17 00:00:00 2001 From: James Ravn Date: Tue, 5 May 2020 13:23:15 +0100 Subject: [PATCH] Make some improvements to java +lsp This is a first pass at making `+lsp` more functional: * Fix lsp not starting automatically when opening java-mode buffers. Placing it in the lsp-java hook does not work. * Enable the code lens for test classes. * Add a keybinding/function to easily update the eclipse LSP server. * Add a keybinding to bring up the lsp-jt-browser (the treemacs based browser that lists all the project tests). * Fix root path for lsp-jt. There are still a lot of rough edges here, and I don't think it's quite usable yet, mostly due to issues around the java test mode (lsp-jt). The other functionality all seems to work well though. --- modules/lang/java/+lsp.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/lang/java/+lsp.el b/modules/lang/java/+lsp.el index ba7f84eb1..34ca2f2b1 100644 --- a/modules/lang/java/+lsp.el +++ b/modules/lang/java/+lsp.el @@ -1,13 +1,25 @@ ;;; lang/java/+lsp.el -*- lexical-binding: t; -*- ;;;###if (featurep! +lsp) +;;;###autoload +(defun +java/update-lsp-server () + (interactive) + (lsp--install-server-internal (gethash 'jdtls lsp-clients) t)) + +(add-hook! java-mode-local-vars #'lsp!) +(map! :map java-mode-map + :localleader + :desc "Update the Eclipse LSP server" "U" #'+java/update-lsp-server + :desc "Open the test browser" "T" #'lsp-jt-browser) + +;; TODO: This fails on the first java buffer opened - complains about the LSP server not having executeCode capabilities. +(defun java--lsp-jt-lens-mode-hook () + (when (derived-mode-p 'java-mode) (lsp-jt-lens-mode))) + (use-package! lsp-java - :after lsp-clients - :hook (java-mode-local-vars . lsp!) + :after (lsp-clients dap-mode) + :hook (lsp-mode . java--lsp-jt-lens-mode-hook) :preface (setq lsp-java-server-install-dir (concat doom-etc-dir "eclipse.jdt.ls/server/") - lsp-java-workspace-dir (concat doom-etc-dir "java-workspace")) - :config - ;; TODO keybinds - ;; TODO treemacs integration (?) - ) + lsp-java-workspace-dir (concat doom-etc-dir "java-workspace") + lsp-jt-root (concat doom-etc-dir "eclipse.jdt.ls/server/java-test/server")))