2018-09-04 13:45:10 +00:00
|
|
|
#+TITLE: dart layer
|
|
|
|
|
2019-05-07 08:53:56 +00:00
|
|
|
#+TAGS: general|layer|multi-paradigm|programming
|
2019-05-05 17:26:40 +00:00
|
|
|
|
2018-09-04 13:45:10 +00:00
|
|
|
[[file:img/dart.png]]
|
|
|
|
|
2019-05-07 20:05:06 +00:00
|
|
|
* Table of Contents :TOC_5_gh:noexport:
|
2018-09-04 13:45:10 +00:00
|
|
|
- [[#description][Description]]
|
|
|
|
- [[#features][Features:]]
|
|
|
|
- [[#install][Install]]
|
2019-12-17 05:53:49 +00:00
|
|
|
- [[#choosing-a-backend][Choosing a backend]]
|
|
|
|
- [[#backends][Backends]]
|
2019-12-23 20:43:50 +00:00
|
|
|
- [[#lsp][LSP]]
|
2018-09-04 13:45:10 +00:00
|
|
|
- [[#flutter-integration][Flutter integration]]
|
2019-12-17 05:53:49 +00:00
|
|
|
- [[#format-on-save][Format on save]]
|
2019-12-24 10:03:00 +00:00
|
|
|
- [[#dart-analyzer-deprecated][Dart analyzer (deprecated)]]
|
2019-12-23 20:43:50 +00:00
|
|
|
- [[#flutter-integration-1][Flutter integration]]
|
|
|
|
- [[#format-on-save-1][Format on save]]
|
2018-09-04 13:45:10 +00:00
|
|
|
- [[#key-bindings][Key bindings]]
|
|
|
|
- [[#normal-mode][Normal mode]]
|
|
|
|
- [[#insert-mode][Insert mode]]
|
|
|
|
- [[#popup-screens][Popup screens]]
|
|
|
|
|
|
|
|
* Description
|
2019-04-12 19:31:31 +00:00
|
|
|
This layer adds support for Dart language, and could be optionally used for Flutter development as well.
|
2018-09-04 13:45:10 +00:00
|
|
|
|
|
|
|
** Features:
|
2019-04-12 19:31:31 +00:00
|
|
|
- Syntax Highlight
|
|
|
|
- Error checking with ~flycheck~
|
|
|
|
- Go to Definition
|
|
|
|
- Dart Analyzer integration
|
|
|
|
- Key bindings
|
2018-09-04 13:45:10 +00:00
|
|
|
|
|
|
|
* Install
|
2019-04-12 19:31:31 +00:00
|
|
|
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
|
|
|
add =dart= to the existing =dotspacemacs-configuration-layers= list in this
|
|
|
|
file.
|
2018-09-04 13:45:10 +00:00
|
|
|
|
2019-12-17 05:53:49 +00:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq-default dotspacemacs-configuration-layers '(dart))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Choosing a backend
|
|
|
|
To choose a default backend set the layer variable =dart-backend=:
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
(setq-default dotspacemacs-configuration-layers '(
|
2019-12-20 22:20:59 +00:00
|
|
|
(dart :variables dart-backend 'lsp)))
|
2019-12-17 05:53:49 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
2019-12-20 22:20:59 +00:00
|
|
|
Alternatively the =lsp= backend will be automatically chosen if
|
|
|
|
you did not specify any value for =dart-backend=.
|
2019-12-17 05:53:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
=lsp= backend:
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
;;; Directory Local Variables
|
|
|
|
;;; For more information see (info "(emacs) Directory Variables")
|
|
|
|
((dart-mode (dart-backend . lsp)))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
* Backends
|
2019-12-20 22:20:59 +00:00
|
|
|
** 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
|
|
|
|
|
2019-12-23 20:43:50 +00:00
|
|
|
*** Flutter integration
|
|
|
|
Flutter comes with a internal Dart SDK, which can be used to provide all the
|
|
|
|
integration tools.
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
(dart :variables lsp-dart-sdk-dir "<flutter-path>/bin/cache/dart-sdk/")
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** Format on save
|
|
|
|
Set the layer variable =lsp-enable-on-type-formatting= to =t= to activate formatting
|
|
|
|
on save.
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
(dart :variables lsp-enable-on-type-formatting t)
|
|
|
|
#+END_SRC
|
|
|
|
|
2019-12-20 22:20:59 +00:00
|
|
|
** Dart analyzer (deprecated)
|
|
|
|
This backend is not longer officially supported from [[https://github.com/bradyt/dart-server][dart-server]] use the LSP backend instead.
|
|
|
|
|
2019-12-17 05:53:49 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(dart :variables dart-server-enable-analysis-server t)
|
2019-12-24 10:03:00 +00:00
|
|
|
#+END_SRC
|
2019-12-17 05:53:49 +00:00
|
|
|
|
|
|
|
[[https://github.com/bradyt/dart-server][dart-server]] will use the =dart= executable location if available on the
|
2019-12-20 22:20:59 +00:00
|
|
|
path, but it is possible to define the location manually. It should point to the folder and end with =/=.
|
2018-09-04 13:45:10 +00:00
|
|
|
|
2019-04-12 19:31:31 +00:00
|
|
|
#+BEGIN_SRC elisp
|
2019-08-09 20:07:07 +00:00
|
|
|
(dart :variables dart-server-sdk-path "~/path/to/dart-sdk/")
|
2019-04-12 19:31:31 +00:00
|
|
|
#+END_SRC
|
2018-09-04 13:45:10 +00:00
|
|
|
|
|
|
|
*** Flutter integration
|
2019-08-09 20:07:07 +00:00
|
|
|
Flutter comes with a internal Dart SDK, which can be used to provide all the
|
|
|
|
integration tools.
|
2018-09-04 13:45:10 +00:00
|
|
|
|
2019-04-12 19:31:31 +00:00
|
|
|
#+BEGIN_SRC elisp
|
2019-08-09 20:07:07 +00:00
|
|
|
(dart :variables dart-server-sdk-path "<flutter-path>/bin/cache/dart-sdk/")
|
2019-04-12 19:31:31 +00:00
|
|
|
#+END_SRC
|
2018-09-04 13:45:10 +00:00
|
|
|
|
2019-12-17 05:53:49 +00:00
|
|
|
*** Format on save
|
2019-12-23 20:43:50 +00:00
|
|
|
Set the layer variable =dart-server-format-on-save= to =t= to activate formatting
|
|
|
|
on save.
|
2019-12-24 10:03:00 +00:00
|
|
|
|
2019-12-17 05:53:49 +00:00
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
(dart :variables dart-server-format-on-save t)
|
2019-04-12 19:31:31 +00:00
|
|
|
#+END_SRC
|
2018-09-04 13:45:10 +00:00
|
|
|
|
2019-09-28 21:01:49 +00:00
|
|
|
For additional variables check the [[https://github.com/bradyt/dart-server][dart-server]] documentation.
|
|
|
|
|
2018-09-04 13:45:10 +00:00
|
|
|
* Key bindings
|
|
|
|
** Normal mode
|
2019-08-09 20:07:07 +00:00
|
|
|
Some of the commands will instantiate a new Dart Analyzer server if necessary,
|
|
|
|
while others work without using a Dart Analyzer connection.
|
2019-04-12 19:31:31 +00:00
|
|
|
|
2019-08-09 20:07:07 +00:00
|
|
|
When ~dart-server-enable-analysis-server~ is enabled, most of the commands
|
|
|
|
become Async, and there might be a delay when executing them.
|
2019-04-12 19:31:31 +00:00
|
|
|
|
|
|
|
| Key binding | Description |
|
|
|
|
|------------------------+---------------------------------------------------|
|
|
|
|
| ~SPC m h h~, ~SPC m ?~ | Displays hover information for the current point. |
|
|
|
|
| ~SPC m h b~ | Displays information at point on a new buffer. |
|
|
|
|
| ~gd~, ~SPC m g~ | Go to definition. |
|
|
|
|
| ~SPC m f d~ | Find members declarations by name. |
|
|
|
|
| ~SPC m f r~ | Find members references by name. |
|
|
|
|
| ~SPC m f d~ | Find top-level declarations by name. |
|
|
|
|
| ~SPC m =~ | Format buffer |
|
2018-09-04 13:45:10 +00:00
|
|
|
|
|
|
|
** Insert mode
|
|
|
|
|
2019-04-12 19:31:31 +00:00
|
|
|
| Key binding | Description |
|
|
|
|
|-------------+--------------------------------------------------|
|
|
|
|
| ~<tab>~ | Expand previous word using Analyzer if available |
|
|
|
|
| ~C-<tab>~ | Expand including parameters |
|
2018-09-04 13:45:10 +00:00
|
|
|
|
|
|
|
** Popup screens
|
|
|
|
|
2019-04-12 19:31:31 +00:00
|
|
|
| Key binding | Description |
|
|
|
|
|-------------+-------------------------------------------|
|
|
|
|
| ~q~ | Close popup |
|
|
|
|
| ~gr~ | Execute last command to repopulate buffer |
|