Emacs Language Server client backed by JavaComp
lsp-javacomp is a lsp-mode client that provides Java code-completion and other IDE features for Emacs. It's backed by JavaComp.
lsp-javacomp is available on MELPA. To install it, first setup
MELPA, then M-x package-install
RET
lsp-javacomp
RET.
After installing it, add the snippet below to your .emacs
file to enable it
for java-mode
:
(require 'lsp-javacomp)
(add-hook 'java-mode-hook #'lsp-javacomp-enable)
I recommend using lsp-javacomp in with [company-lsp][compan-lsp]. If you are
lazy-loading company-lsp, make sure it's loaded before calling
lsp-javacomp-enable
. You can lazily load lsp-javacomp and company-lsp with
use-package:
(use-package lsp-javacomp
:commands lsp-javacomp-enable
:init
(add-hook 'java-mode-hook
(lambda ()
;; Load company-lsp before enabling lsp-javacomp, so that function
;; parameter snippet works.
(require 'company-lsp)
(lsp-javacomp-enable)
;; Use company-lsp as the company completion backend
(set (make-variable-buffer-local 'company-backends) '(company-lsp))
;; Optional company-mode settings
(set (make-variable-buffer-local 'company-idle-delay) 0.1)
(set (make-variable-buffer-local 'company-minimum-prefix-length) 1)))
;; Optional, make sure JavaComp is installed. See below.
:config
(lsp-javacomp-install-server)))
After installing lsp-javacomp to your Emacs, you can use M-x lsp-javacomp-install-server
to install the JavaComp server.
If you want to update to the latest version of JavaComp, you can use M-x lsp-javacomp-update-server
.
Alternatively, you can build or download the jar file manually. You must rename
the jar file to javacomp.jar
and put it into the directory specified by the
lsp-javacomp-server-install-dir
variable. The default value of
lsp-javacomp-server-install-dir
is ~/.emacs.d/javacomp/
.
If you don't use company-lsp, you can use the vanilla completion-at-point
implemented by lsp-mode.
Run M-x completion-at-point
in a .java file buffer to get completion
candidates. The default key binding is C-M-i
.