Revise dart layer
I have: - Revised the documentation to be more clear about the possible backends - Simplified the lsp setup code - Removed redundant loading of company-lsp (is done by lsp-mode already) - Made lsp the default backend for dart and mentioned that the analyser is deprecated
This commit is contained in:
parent
ffd8ad2410
commit
ffccb17426
|
@ -1533,7 +1533,7 @@ Other:
|
|||
- Fixed =d-mode= flycheck imports on dub projects (thanks to Dietrich Daroch)
|
||||
**** Dart
|
||||
- Improvements:
|
||||
- Added =LSP= support (thanks to Mathieu Post)
|
||||
- Added =LSP= support (thanks to Mathieu Post and Takeshi Tsukamoto)
|
||||
- Added =Flutter= support (thanks to Mathieu Post)
|
||||
- Fixes:
|
||||
- Added =dart-server= package (thanks to duianto)
|
||||
|
|
|
@ -43,11 +43,11 @@ To choose a default backend set the layer variable =dart-backend=:
|
|||
|
||||
#+BEGIN_SRC elisp
|
||||
(setq-default dotspacemacs-configuration-layers '(
|
||||
(dart :variables dart-backend 'analyzer)))
|
||||
(dart :variables dart-backend 'lsp)))
|
||||
#+END_SRC
|
||||
|
||||
Alternatively the =lsp= backend will be automatically chosen if the layer =lsp=
|
||||
is used and you did not specify any value for =dart-backend=.
|
||||
Alternatively the =lsp= backend will be automatically chosen if
|
||||
you did not specify any value for =dart-backend=.
|
||||
|
||||
Backend can be chosen on a per project basis using directory local variables
|
||||
(files named =.dir-locals.el= at the root of a project), an example to use the
|
||||
|
@ -60,7 +60,27 @@ Backend can be chosen on a per project basis using directory local variables
|
|||
#+END_SRC
|
||||
|
||||
* Backends
|
||||
** Dart analyzer
|
||||
** LSP
|
||||
This is the recommended backend it is a full IDE server using the standard
|
||||
language server protocol to communicate with emacs.
|
||||
|
||||
Current versions of the dart-sdk ship with lsp support directly integrated in
|
||||
the =dart-server=. You do not need to worry about starting and stopping the
|
||||
server this will be done by spacemacs automatically.
|
||||
|
||||
However to get all features make sure that you also load the
|
||||
auto-completion and syntax-checking layer in your dotfile.
|
||||
|
||||
Emacs will look in the standard SDK location for the lsp server.
|
||||
If this is not working for you, please set the custom path via =lsp-dart-sdk-dir=.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(dart :variables lsp-dart-sdk-dir "~/path/to/dart-sdk/")
|
||||
#+END_SRC
|
||||
|
||||
** Dart analyzer (deprecated)
|
||||
This backend is not longer officially supported from [[https://github.com/bradyt/dart-server][dart-server]] use the LSP backend instead.
|
||||
|
||||
Dart analyzer supported via [[https://github.com/bradyt/dart-server][dart-server]]. You need to enable =dart-server-enable-analysis-server=
|
||||
to use analyzer features.
|
||||
|
||||
|
@ -69,8 +89,7 @@ to use analyzer features.
|
|||
#+end_src
|
||||
|
||||
[[https://github.com/bradyt/dart-server][dart-server]] will use the =dart= executable location if available on the
|
||||
execution path, but it is possible to define the location manually. It should
|
||||
point to the folder, and end with =/=.
|
||||
path, but it is possible to define the location manually. It should point to the folder and end with =/=.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(dart :variables dart-server-sdk-path "~/path/to/dart-sdk/")
|
||||
|
@ -91,19 +110,6 @@ integration tools.
|
|||
|
||||
For additional variables check the [[https://github.com/bradyt/dart-server][dart-server]] documentation.
|
||||
|
||||
** LSP
|
||||
You must add lsp to the existing dotspacemacs-configuration-layers in your ~/.spacemacs.
|
||||
|
||||
Consult the installation command for the desired language server found at lsp-mode for instructions.
|
||||
|
||||
To enable auto-completion, ensure that the auto-completion layer is enabled.
|
||||
|
||||
If you want to use custom dart sdk location, set it to =lsp-dart-sdk-dir=.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(dart :variables lsp-dart-sdk-dir "~/path/to/dart-sdk/")
|
||||
#+END_SRC
|
||||
|
||||
* Key bindings
|
||||
** Normal mode
|
||||
Some of the commands will instantiate a new Dart Analyzer server if necessary,
|
||||
|
|
|
@ -10,10 +10,8 @@
|
|||
;;; License: GPLv3
|
||||
|
||||
;; Variables
|
||||
|
||||
(defvar dart-backend nil
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `analyzer' `lsp'.
|
||||
If `nil' then `analyzer' is the default backend unless `lsp' layer is used.")
|
||||
|
||||
(spacemacs|define-jump-handlers dart-mode)
|
||||
|
||||
(defvar dart-backend 'lsp
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `analyzer' and `lsp'.")
|
||||
|
|
|
@ -12,46 +12,7 @@
|
|||
|
||||
;; backend
|
||||
|
||||
(defun spacemacs//dart-backend ()
|
||||
"Returns selected backend."
|
||||
(if dart-backend
|
||||
dart-backend
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'analyzer))))
|
||||
|
||||
(defun spacemacs//dart-setup-backend ()
|
||||
(pcase (spacemacs//dart-backend)
|
||||
(`analyzer (spacemacs//dart-setup-analyzer))
|
||||
(`lsp (spacemacs//dart-setup-lsp))))
|
||||
|
||||
(defun spacemacs//dart-setup-company ()
|
||||
(pcase (spacemacs//dart-backend)
|
||||
(`lsp (spacemacs//dart-setup-company-lsp))))
|
||||
|
||||
|
||||
;; analyzer
|
||||
|
||||
(defun spacemacs//dart-setup-analyzer ()
|
||||
(dart-server))
|
||||
|
||||
|
||||
;; lsp
|
||||
|
||||
(defun spacemacs//dart-setup-lsp ()
|
||||
"Setup lsp backend"
|
||||
(if (configuration-layer/layer-used-p 'lsp)
|
||||
(lsp)
|
||||
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
||||
|
||||
(defun spacemacs//dart-setup-company-lsp ()
|
||||
"Setup lsp auto-completion"
|
||||
(if (configuration-layer/layer-used-p 'lsp)
|
||||
(progn
|
||||
(spacemacs|add-company-backends
|
||||
:backends company-lsp
|
||||
:modes dart-mode
|
||||
:append-hooks nil
|
||||
:call-hooks t)
|
||||
(company-mode))
|
||||
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
||||
(pcase dart-backend
|
||||
(`analyzer (dart-server))
|
||||
(`lsp (lsp))))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; packages.el --- dart layer packages file for Spacemacs.
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;; Copyright (c) 2012-2019 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Bruno Tavares <connect+spacemacs@bltavares.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
|
@ -9,14 +9,11 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defconst dart-packages
|
||||
'(
|
||||
dart-mode
|
||||
dart-server
|
||||
company
|
||||
flutter
|
||||
(dart-server :toggle (eq dart-backend 'analyzer))
|
||||
(flutter (eq dart-backend 'analyzer))
|
||||
flycheck
|
||||
))
|
||||
|
||||
|
@ -78,10 +75,5 @@
|
|||
(spacemacs/set-leader-keys-for-major-mode 'dart-mode
|
||||
"xx" 'flutter-run-or-hot-reload))))
|
||||
|
||||
(defun dart/post-init-company ()
|
||||
(add-hook 'dart-mode-local-vars-hook #'spacemacs//dart-setup-company))
|
||||
|
||||
(defun dart/post-init-flycheck ()
|
||||
(spacemacs/enable-flycheck 'dart-mode))
|
||||
|
||||
;;; packages.el ends here
|
||||
|
|
Loading…
Reference in New Issue