[elm] Add lsp support
This commit is contained in:
parent
39de9ff0af
commit
56338b537d
|
@ -13,8 +13,13 @@
|
|||
- [[#macos-and-windows-installers][macOS and Windows installers]]
|
||||
- [[#universal-installer-using-npm][Universal installer using npm]]
|
||||
- [[#source-code][Source code]]
|
||||
- [[#elm-oracle][elm-oracle]]
|
||||
- [[#elm-format][elm-format]]
|
||||
- [[#elm-test][elm-test]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#choosing-a-backend][Choosing a backend]]
|
||||
- [[#company-elm][Company-elm]]
|
||||
- [[#elm-oracle][elm-oracle]]
|
||||
- [[#lsp][LSP]]
|
||||
- [[#basic-usage-tips][Basic usage tips]]
|
||||
- [[#compilation][Compilation]]
|
||||
- [[#reactor][Reactor]]
|
||||
|
@ -42,8 +47,7 @@ It relies on [[https://github.com/jcollard/elm-mode][elm-mode]] and [[https://gi
|
|||
** Features:
|
||||
- Syntax highlighting.
|
||||
- Intelligent indentation
|
||||
- Auto-completion integration for company (default) or auto-complete modes,
|
||||
with using elm-oracle
|
||||
- Auto-completion integration for company (default) or auto-complete modes
|
||||
- Syntax checking support using flycheck
|
||||
- Integration with elm-make
|
||||
- Integration with elm-repl
|
||||
|
@ -88,7 +92,55 @@ run, see this issue [[https://github.com/kevva/elm-bin/issues/28][https://github
|
|||
To build from source, see instructions here:
|
||||
[[https://github.com/elm-lang/elm-platform][https://github.com/elm-lang/elm-platform]]
|
||||
|
||||
** elm-oracle
|
||||
** elm-format
|
||||
=elm-format= can be used to format elm code according to a standard set of
|
||||
rules.
|
||||
|
||||
To install =elm-format= run below command:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
npm install --global elm-format
|
||||
#+END_SRC
|
||||
|
||||
If this does not work for you please check [[https://github.com/avh4/elm-format][here]].
|
||||
|
||||
Also, note that if you use homebrew to install =elm-format= the installed exe
|
||||
has a version suffix, the installed command name can be set in your
|
||||
=~/spacemacs=:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(elm :variables
|
||||
elm-format-command "elm-format-0.17")
|
||||
#+END_SRC
|
||||
|
||||
** elm-test
|
||||
=elm-test= can be used to run unit tests.
|
||||
|
||||
To install =elm-test= run below command:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
npm install --global elm-test
|
||||
#+END_SRC
|
||||
|
||||
* 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-elm
|
||||
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 programs
|
||||
are edited. To set explicitly set the following in your
|
||||
dotfile:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(elm :variables elm-backend 'company-elm)
|
||||
#+END_SRC
|
||||
|
||||
**** elm-oracle
|
||||
=elm-oracle= can be used to show type signatures and docs for tokens under the
|
||||
cursor and provide support for auto-completion, but it is not part of the
|
||||
standard elm-platform.
|
||||
|
@ -103,22 +155,33 @@ run this command:
|
|||
npm install -g elm-oracle
|
||||
#+END_SRC
|
||||
|
||||
** elm-format
|
||||
=elm-format= can be used to format elm code according to a standard set of
|
||||
rules.
|
||||
*** 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 an elm file is opened. The key bindings 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 install =elm-format= follow the instructions for the version of elm
|
||||
installed: [[https://github.com/avh4/elm-format]]
|
||||
|
||||
Also, note that if you use homebrew to install =elm-format= the installed exe
|
||||
has a version suffix, the installed command name can be set in your
|
||||
=~/spacemacs=:
|
||||
To set explicitly do the following in your dotfile:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(elm :variables
|
||||
elm-format-command "elm-format-0.17")
|
||||
elm-backend 'lsp)
|
||||
#+END_SRC
|
||||
|
||||
For this to work you will also need to install
|
||||
the lsp server and separate dependencies with below
|
||||
command:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
npm install -g elm-analysis @elm-tooling/elm-language-server
|
||||
#+END_SRC
|
||||
|
||||
NOTE: Key bindings 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.
|
||||
|
||||
* Basic usage tips
|
||||
** Compilation
|
||||
To control the name of the compiled JavaScript file, use ~SPC m c B~ instead of
|
||||
|
|
19
layers/+lang/elm/config.el
Normal file
19
layers/+lang/elm/config.el
Normal file
|
@ -0,0 +1,19 @@
|
|||
;;; config.el --- Elm Layer packages 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
|
||||
|
||||
(spacemacs|define-jump-handlers elm-mode)
|
||||
|
||||
(defvar elm-backend nil
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `lsp' and `company-elm'.
|
||||
If `nil' then 'company-elm` is the default backend unless `lsp' layer is used")
|
|
@ -1,6 +1,6 @@
|
|||
;;; funcs.el --- Elm Layer 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,9 +9,41 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(defun spacemacs//elm-backend ()
|
||||
"Returns selected backend."
|
||||
(if elm-backend
|
||||
elm-backend
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'company-elm))))
|
||||
|
||||
(defun spacemacs//elm-setup-company ()
|
||||
"Conditionally setup company based on backend."
|
||||
(pcase (spacemacs//elm-backend)
|
||||
;; Activate lsp company explicitly to activate
|
||||
;; standard backends as well
|
||||
(`lsp (spacemacs|add-company-backends
|
||||
:backends company-capf
|
||||
:modes elm-mode))
|
||||
(`company-elm (spacemacs|add-company-backends
|
||||
:backends elm-company
|
||||
:modes elm-mode))))
|
||||
|
||||
(defun spacemacs//elm-setup-backend ()
|
||||
"Conditionally setup elm backend."
|
||||
(spacemacs/init-elm-mode)
|
||||
(pcase (spacemacs//elm-backend)
|
||||
(`lsp (lsp))
|
||||
(`company-elm (elm-oracle-setup-completion))))
|
||||
|
||||
|
||||
;; elm-mode
|
||||
|
||||
(defun spacemacs/init-elm-mode ()
|
||||
"Disable electric-indent-mode and let indentation cycling feature work"
|
||||
(if (fboundp 'electric-indent-local-mode)
|
||||
(electric-indent-local-mode -1)))
|
||||
|
||||
(defun spacemacs/elm-compile-buffer-output ()
|
||||
(interactive)
|
||||
(let* ((fname (format "%s.js" (downcase (file-name-base (buffer-file-name))))))
|
||||
|
|
14
layers/+lang/elm/layers.el
Normal file
14
layers/+lang/elm/layers.el
Normal file
|
@ -0,0 +1,14 @@
|
|||
;;; layers.el --- Elm 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 'elm-backend)
|
||||
(eq elm-backend 'lsp))
|
||||
(configuration-layer/declare-layer-dependencies '(lsp)))
|
|
@ -1,6 +1,6 @@
|
|||
;;; packages.el --- elm 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,23 +9,21 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(setq elm-packages
|
||||
'(
|
||||
company
|
||||
elm-mode
|
||||
elm-test-runner
|
||||
flycheck
|
||||
(flycheck-elm :requires flycheck)
|
||||
popwin
|
||||
smartparens
|
||||
))
|
||||
(defconst elm-packages
|
||||
'(
|
||||
company
|
||||
elm-mode
|
||||
elm-test-runner
|
||||
flycheck
|
||||
(flycheck-elm :requires flycheck)
|
||||
popwin
|
||||
smartparens))
|
||||
|
||||
(defun elm/post-init-company ()
|
||||
(spacemacs|add-company-backends :backends company-elm :modes elm-mode)
|
||||
(add-hook 'elm-mode-hook 'elm-oracle-setup-completion))
|
||||
(spacemacs//elm-setup-company))
|
||||
|
||||
(defun elm/post-init-flycheck ()
|
||||
(add-hook 'elm-mode-hook 'flycheck-mode))
|
||||
(spacemacs/enable-flycheck 'elm-mode))
|
||||
|
||||
(defun elm/init-flycheck-elm ()
|
||||
"Initialize flycheck-elm"
|
||||
|
@ -37,28 +35,31 @@
|
|||
"Initialize elm-mode"
|
||||
(use-package elm-mode
|
||||
:mode ("\\.elm\\'" . elm-mode)
|
||||
:defer t
|
||||
:init
|
||||
(progn
|
||||
(spacemacs/register-repl 'elm-mode 'elm-repl-load "elm")
|
||||
|
||||
(defun spacemacs/init-elm-mode ()
|
||||
"Disable electric-indent-mode and let indentation cycling feature work"
|
||||
(if (fboundp 'electric-indent-local-mode)
|
||||
(electric-indent-local-mode -1)))
|
||||
|
||||
(add-hook 'elm-mode-hook 'spacemacs/init-elm-mode))
|
||||
(add-hook 'elm-mode-hook 'spacemacs//elm-setup-backend))
|
||||
:config
|
||||
(progn
|
||||
;; Bind non-lsp keys
|
||||
(when (eq (spacemacs//elm-backend) 'company-elm)
|
||||
(spacemacs/set-leader-keys-for-major-mode 'elm-mode
|
||||
;; format
|
||||
"=b" 'elm-format-buffer
|
||||
;; oracle
|
||||
"hh" 'elm-oracle-doc-at-point
|
||||
"ht" 'elm-oracle-type-at-point)
|
||||
|
||||
;; Bind prefixes
|
||||
(dolist (x '(("m=" . "format")
|
||||
("mh" . "help")
|
||||
("mg" . "goto")
|
||||
("mr" . "refactor")))
|
||||
(spacemacs/declare-prefix-for-mode 'elm-mode (car x) (cdr x))))
|
||||
|
||||
;; Bind general keys
|
||||
(spacemacs/set-leader-keys-for-major-mode 'elm-mode
|
||||
;; format
|
||||
"=b" 'elm-mode-format-buffer
|
||||
;; make
|
||||
"cb" 'elm-compile-buffer
|
||||
"cB" 'spacemacs/elm-compile-buffer-output
|
||||
"cm" 'elm-compile-main
|
||||
;; oracle
|
||||
"hh" 'elm-oracle-doc-at-point
|
||||
"ht" 'elm-oracle-type-at-point
|
||||
;; refactoring
|
||||
"ri" 'elm-sort-imports
|
||||
;; repl
|
||||
|
@ -68,6 +69,10 @@
|
|||
"sF" 'spacemacs/elm-repl-push-decl-focus
|
||||
"sr" 'elm-repl-push
|
||||
"sR" 'spacemacs/elm-repl-push-focus
|
||||
;; make
|
||||
"cb" 'elm-compile-buffer
|
||||
"cB" 'spacemacs/elm-compile-buffer-output
|
||||
"cm" 'elm-compile-main
|
||||
;; reactor
|
||||
"Rn" 'elm-preview-buffer
|
||||
"Rm" 'elm-preview-main
|
||||
|
@ -76,12 +81,10 @@
|
|||
"pc" 'elm-package-catalog
|
||||
"pd" 'elm-documentation-lookup)
|
||||
|
||||
(dolist (x '(("m=" . "format")
|
||||
;; Bind prefixes
|
||||
(dolist (x '(("mp" . "package")
|
||||
("mc" . "compile")
|
||||
("mh" . "help")
|
||||
("mp" . "package")
|
||||
("mR" . "reactor")
|
||||
("mr" . "refactor")
|
||||
("ms" . "repl")))
|
||||
(spacemacs/declare-prefix-for-mode 'elm-mode (car x) (cdr x)))
|
||||
|
||||
|
@ -105,8 +108,7 @@
|
|||
"tp" 'elm-test-runner-run-project
|
||||
"tr" 'elm-test-runner-rerun
|
||||
"tw" 'elm-test-runner-watch
|
||||
"t TAB" 'elm-test-runner-toggle-test-and-target
|
||||
))))
|
||||
"t TAB" 'elm-test-runner-toggle-test-and-target))))
|
||||
|
||||
(defun elm/pre-init-popwin ()
|
||||
(spacemacs|use-package-add-hook popwin
|
||||
|
|
Loading…
Reference in a new issue