[groovy] Add lsp server support

This commit is contained in:
Maximilian Wolff 2020-07-05 23:58:55 +02:00
parent 7f2dfe9c91
commit eacab70047
No known key found for this signature in database
GPG Key ID: 2DD07025BFDBD89A
5 changed files with 123 additions and 12 deletions

View File

@ -8,6 +8,10 @@
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#configuration][Configuration]]
- [[#choosing-a-backend][Choosing a backend]]
- [[#company-groovy][Company-groovy]]
- [[#lsp][LSP]]
- [[#key-bindings][Key bindings]]
- [[#imports][Imports]]
- [[#repl][REPL]]
@ -16,15 +20,60 @@
This layer supports [[http://www.groovy-lang.org/][Groovy]] development in Spacemacs.
** Features:
- Basic dabbrev auto-completion with company
- Auto-completion
- Syntax-checking
- Auto-generate imports with [[https://github.com/mbezjak/emacs-groovy-imports][groovy-imports]]
- Groovy REPL integration
- Syntax highlighting
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =groovy= to the existing =dotspacemacs-configuration-layers= list in this
file.
* Configuration
All layer configurations can be done by setting layer variables in your dotfile.
No custom user config lines are necessary
** Choosing a backend
This layer provides two alternative backends to choose from.
*** Company-groovy
This is the default choice if nothing is set and no lsp layer
is loaded in your dotfile. This mode only provides very
limited IDE capabilities. Used best if only small scripts
are edited. To set explicitly set the following in your
dotfile:
#+BEGIN_SRC emacs-lisp
(groovy :variables groovy-backend 'company-groovy)
#+END_SRC
*** LSP
For proper IDE support this backend should be used. It is
based on an external server which will be started automatically
by emacs, once a groovy file is opened. The keybindings are
the same for all lsp modes so if you are already familiar with
one you should be able to work the same in all modes.
To set explicitly do the following in your dotfile:
#+BEGIN_SRC emacs-lisp
(groovy :variables
groovy-backend 'lsp
lsp-jar-path "path/to/groovy/lsp/jar.jar"
#+END_SRC
For this to work you will also need to obtain
the latest version of the lsp server from [[https://github.com/prominic/groovy-language-server][here]].
The path to the server jar must be given in the layer
variable =lsp-jar-path=.
NOTE: Keybindings for LSP are defined in the
LSP layer. Also it is advisable to have a look
at the autocomplete layer for an optimal
intellisense config for LSP.
* Key bindings
** Imports

View File

@ -0,0 +1,20 @@
;;; config.el --- Groovy layer configuration File for Spacemacs
;;
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Maximilian Wolff <smile13241324@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Variables
(defvar groovy-backend nil
"The backend to use for IDE features.
Possible values are `lsp' and `company-groovy'.
If `nil' then 'company-groovy` is the default backend unless `lsp' layer is used")
(defvar lsp-jar-path "~/groovy-lsp-all.jar"
"The path to the lsp jar file")

View File

@ -1,6 +1,6 @@
;;; funcs.el --- Groovy functions File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
@ -9,6 +9,30 @@
;;
;;; License: GPLv3
(defun spacemacs//groovy-backend ()
"Return selected backend."
(if groovy-backend
groovy-backend
(cond
((configuration-layer/layer-used-p 'lsp) 'lsp)
(t 'company-groovy))))
(defun spacemacs//groovy-setup-company ()
"Conditionally setup company based on backend."
(pcase (spacemacs//groovy-backend)
;; Activate lsp company explicitly to activate
;; standard backends as well
(`lsp (spacemacs|add-company-backends
:backends company-capf
:modes groovy-mode))
(`company-groovy (spacemacs|add-company-backends)
:modes groovy-mode)))
(defun spacemacs//groovy-setup-backend ()
"Conditionally setup groovy backend."
(pcase (spacemacs//groovy-backend)
(`lsp (lsp))))
;; REPL

View File

@ -0,0 +1,14 @@
;;; layers.el --- Groovy Layer layers File for Spacemacs
;;
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Maximilian Wolff <smile13241324@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(when (and (boundp 'groovy-backend)
(eq groovy-backend 'lsp))
(configuration-layer/declare-layer-dependencies '(lsp)))

View File

@ -1,6 +1,6 @@
;;; packages.el --- Groovy Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
@ -9,16 +9,18 @@
;;
;;; License: GPLv3
(setq groovy-packages
'(
company
groovy-imports
groovy-mode
org
))
(defconst groovy-packages
'(
company
groovy-imports
groovy-mode
org))
(defun groovy/post-init-company ()
(spacemacs|add-company-backends :modes groovy-mode))
(spacemacs//groovy-setup-company))
(defun groovy/post-init-flycheck ()
(spacemacs/enable-flycheck 'groovy-mode))
(defun groovy/init-groovy-imports ()
(use-package groovy-imports
@ -34,6 +36,7 @@
:defer t
:init
(progn
(setq lsp-groovy-server-file lsp-jar-path)
(spacemacs/declare-prefix-for-mode 'groovy-mode "ms" "REPL")
(spacemacs/set-leader-keys-for-major-mode 'groovy-mode
"'" 'run-groovy
@ -43,7 +46,8 @@
"sf" 'groovy-send-definition
"si" 'run-groovy
"sR" 'spacemacs/groovy-send-region-switch
"sr" 'groovy-send-region))))
"sr" 'groovy-send-region)
(add-hook 'groovy-mode-hook #'spacemacs//groovy-setup-backend))))
(defun groovy/pre-init-org ()
(spacemacs|use-package-add-hook org