Add support for DAP and lsp-treeview in scala layer

This is squash commit including below commits:

* Add support for DAP and lsp-treeview in scala layer
* Address notes from code review.
This commit is contained in:
Rodolfo Hansen 2020-04-03 18:00:45 +02:00 committed by GitHub
parent 757dcbf29d
commit 7854e57efb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 13 deletions

View file

@ -3020,6 +3020,7 @@ Other:
- Added scala-lsp and metals as an additional backend for scala
(thanks to Rodolfo Hansen)
- Disabled =sbt-supershell= in =sbt-mode= (thanks to Rodolfo Hansen)
- Enable new DAP and lsp-treemacs integration via metals (thanks to Rodolfo Hansen)
**** Scheme
- Added missing =parinfer= package declaration (thanks to Kalle Lindqvist)
- Update install docs for Chicken 5 changes (thanks to Grant Shangreaux)

View file

@ -17,9 +17,11 @@
- [[#usage][Usage]]
- [[#scalastyle][Scalastyle]]
- [[#use-java-doc-style][Use Java doc-style]]
- [[#enable-debug-adapter-protocol-dap][Enable Debug Adapter Protocol (DAP)]]
- [[#automatically-show-the-type-of-the-symbol-under-the-cursor][Automatically show the type of the symbol under the cursor]]
- [[#automatically-insert-asterisk-in-multiline-comments][Automatically insert asterisk in multiline comments]]
- [[#automatically-replace-arrows-with-unicode-ones][Automatically replace arrows with unicode ones]]
- [[#enable-gtags-as-a-fallback-navigation-utility][Enable GTags as a fallback navigation utility]]
- [[#auto-start][Auto-start]]
- [[#key-bindings][Key bindings]]
- [[#ensime][Ensime]]
@ -43,13 +45,16 @@ This layer adds support for the Scala language to Spacemacs.
** Features:
- Syntax highlighting
- Support for language backend. Either using [[https://ensime.github.io/][ENSIME]] or [[https://scalameta.org/metals/][Metals]]
- Debugging support via dap
- Auto-completion
- Treeview support for viewing project structure and triggering compilation
- Syntax-checking
- Refactoring
- Incremental compilation
- Scala Repl
- Style linting
- Eldoc integration
- Optional GGTags search
- Test execution directly from Emacs
- Automatic replacement of ASCII arrows with unicode ones
@ -174,6 +179,9 @@ To enable =java-doc-style=, set the variable =scala-indent:use-javadoc-style= to
(scala :variables scala-indent:use-javadoc-style t)))
#+END_SRC
* Enable Debug Adapter Protocol (DAP)
The metals backend enables integration with the DAP layer for debugging support.
* Automatically show the type of the symbol under the cursor
To enable the feature =ensime-type-at-point= when cursor moves, set the
variable =scala-enable-eldoc= to =t=.
@ -207,6 +215,16 @@ the ascii arrows back.
(scala :variables scala-use-unicode-arrows t)))
#+END_SRC
* Enable GTags as a fallback navigation utility
To enable gtags when in scala-mode, in case metals, or, ensime are not fully
functioning set the variable =scala-enable-gtags= to =t=.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(scala :variables scala-enable-gtags t)))
#+END_SRC
* Auto-start
If you prefer to have the backend start when you load a scala file, you can enable it
with

View file

@ -14,6 +14,9 @@
(defvar scala-enable-eldoc nil
"If non nil then eldoc-mode is enabled in the scala layer.")
(defvar scala-enable-gtags nil
"If non nil then gtags is enabled in the scala layer.")
(defvar scala-auto-insert-asterisk-in-comments nil
"If non-nil automatically insert leading asterisk in multi-line comments.")

View file

@ -54,6 +54,16 @@
"Setup LSP metals for Scala."
(add-hook 'scala-mode-hook #'lsp))
(defun spacemacs//scala-setup-dap ()
"Setup DAP in metals for Scala."
(when (spacemacs//scala-backend-metals-p)
(add-hook 'scala-mode-hook #'dap-mode)))
(defun spacemacs//scala-setup-treeview ()
"Setup lsp-treemacs for Scala."
(lsp-metals-treeview-enable t)
(setq lsp-metals-treeview-show-when-views-received t))
(defun spacemacs//scala-disable-flycheck-scala ()
(push 'scala flycheck-disabled-checkers))

View file

@ -13,4 +13,4 @@
(when (and (boundp 'scala-backend)
(eq scala-backend 'scala-metals))
(configuration-layer/declare-layer-dependencies '(lsp)))
(configuration-layer/declare-layer-dependencies '(dap)))

View file

@ -11,14 +11,18 @@
(setq scala-packages
'(
(ensime :toggle (spacemacs//scala-backend-ensime-p))
lsp-mode
ggtags
dap-mode
eldoc
flycheck
flyspell
lsp-treemacs
counsel-gtags
ggtags
helm-gtags
noflet
scala-mode
(ensime :toggle (spacemacs//scala-backend-ensime-p))
sbt-mode
scala-mode
))
(defun scala/post-init-eldoc ()
@ -161,18 +165,15 @@
(spacemacs/enable-flycheck 'scala-mode)
;; Don't use scala checker if ensime mode is active, since it provides
;; better error checking.
(when spacemacs//scala-backend-ensime-p
(when (spacemacs//scala-backend-ensime-p)
(with-eval-after-load 'flycheck
(add-hook 'ensime-mode-hook 'spacemacs//scala-disable-flycheck-scala))))
(defun scala/post-init-flyspell ()
(spell-checking/add-flyspell-hook 'scala-mode)
(when spacemacs//scala-backend-ensime-p
(when (spacemacs//scala-backend-ensime-p)
(add-hook 'scala-mode-hook #'spacemacs//scala-setup-ensime-flyspell)))
(defun scala/init-noflet ()
(use-package noflet))
(defun scala/init-sbt-mode ()
(use-package sbt-mode
:defer t
@ -268,15 +269,26 @@ If it's part of a left arrow (`<-'),replace it with the unicode arrow."
scala-indent:default-run-on-strategy
scala-indent:operator-strategy))))
(defun scala/pre-init-dap-mode ()
(add-to-list 'spacemacs--dap-supported-modes 'scala-mode)
(spacemacs//scala-setup-dap))
(defun scala/post-init-lsp-mode ()
(when (spacemacs//scala-backend-metals-p)
(spacemacs//scala-setup-metals)))
(defun scala/post-init-lsp-treemacs ()
(when (spacemacs//scala-backend-metals-p)
(spacemacs//scala-setup-treeview)))
(defun scala/post-init-ggtags ()
(add-hook 'scala-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(when scala-enable-gtags
(add-hook 'scala-mode-local-vars-hook #'spacemacs/ggtags-mode-enable)))
(defun scala/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'scala-mode))
(when scala-enable-gtags
(spacemacs/counsel-gtags-define-keys-for-mode 'scala-mode)))
(defun scala/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'scala-mode))
(when scala-enable-gtags
(spacemacs/helm-gtags-define-keys-for-mode 'scala-mode)))