This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/dart/README.org
2019-12-20 19:32:36 +01:00

4.8 KiB

dart layer

/TakeV/spacemacs/media/commit/ffd8ad24109711063bce58ad8585da732281fc08/layers/+lang/dart/img/dart.png

Description

This layer adds support for Dart language, and could be optionally used for Flutter development as well.

Features:

  • Syntax Highlight
  • Error checking with flycheck
  • Go to Definition
  • Dart Analyzer integration
  • Key bindings

Install

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.

  (setq-default dotspacemacs-configuration-layers '(dart))

Choosing a backend

To choose a default backend set the layer variable dart-backend:

  (setq-default dotspacemacs-configuration-layers '(
    (dart :variables dart-backend 'analyzer)))

Alternatively the lsp backend will be automatically chosen if the layer lsp is used and 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 lsp backend:

  ;;; Directory Local Variables
  ;;; For more information see (info "(emacs) Directory Variables")
  ((dart-mode (dart-backend . lsp)))

Backends

Dart analyzer

Dart analyzer supported via dart-server. You need to enable dart-server-enable-analysis-server to use analyzer features.

  (dart :variables dart-server-enable-analysis-server t)

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 /.

  (dart :variables dart-server-sdk-path "~/path/to/dart-sdk/")

Flutter integration

Flutter comes with a internal Dart SDK, which can be used to provide all the integration tools.

  (dart :variables dart-server-sdk-path "<flutter-path>/bin/cache/dart-sdk/")

Format on save

  (dart :variables dart-server-format-on-save t)

For additional variables check the 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.

  (dart :variables lsp-dart-sdk-dir "~/path/to/dart-sdk/")

Key bindings

Normal mode

Some of the commands will instantiate a new Dart Analyzer server if necessary, while others work without using a Dart Analyzer connection.

When dart-server-enable-analysis-server is enabled, most of the commands become Async, and there might be a delay when executing them.

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

Insert mode

Key binding Description
<tab> Expand previous word using Analyzer if available
C-<tab> Expand including parameters

Popup screens

Key binding Description
q Close popup
gr Execute last command to repopulate buffer