Emacs Dart IDE using lsp-mode to connect to Dart Analysis Server.
LSP works great with Flutter, but there are also other packages that may help to improve your development, for more info see Additional packages.
An example with a minimal configuration to start using lsp-dart
:
(use-package lsp-mode :ensure t)
(use-package lsp-dart
:ensure t
:hook (dart-mode . lsp))
;; Optional packages
(use-package lsp-ui :ensure t)
(use-package company-capf :ensure t)
Besides the lsp-mode
features, lsp-dart
implements the custom methods features from the dart_analysis_server
.
lsp-dart
uses lsp-treemacs
for rendering some tree views features.
lsp-dart-show-outline
lsp-dart-show-flutter-outline
lsp-dart-run-test-file
- Run all tests from current test buffer.
lsp-dart-run-test-at-point
- Run single test at point.
Running a test interactively:
Display the flutter colors on left fringe.
You can disable the feature setting lsp-dart-flutter-fringe-colors
to nil
.
Display widget guide lines from parent to child widgets on flutter.
You can disable the feature setting lsp-dart-flutter-widget-guides
to nil
.
For debugging, lsp-dart
uses dap-mode
.
You only need to run dap-dart-setup
one time to setup the debugger to your Emacs and dap-debug
to start the debug.
lsp-dart
support Flutter debugging too via dap-debug
with an option to select the device to debug.
You can also open the Dart DevTools on the current debug session with lsp-dart-dap-devtools-open
.
Variable | Description | Default |
---|---|---|
lsp-dart-project-sdk-dir |
Install directory for dart-sdk | $PATH |
lsp-dart-project-flutter-command |
The flutter executable path | "flutter" that may be in the $PATH . |
lsp-dart-server-command |
analysis_server executable to use |
Check source file |
lsp-dart-only-analyze-projects-with-open-files |
Analysis will only be performed for projects that have open files rather than the root workspace folder | t |
lsp-dart-suggest-from-unimported-libraries |
Completion will not include symbols that are not already imported into the current file. | t |
lsp-dart-closing-labels |
Enable the closing labels feature on server lsp | t |
lsp-dart-closing-labels-prefix |
The prefix string to be concatenated with the closing label | "" |
lsp-dart-closing-labels-size |
The font size factor to be multiplied by the closing labels font size | 0.9 |
lsp-dart-outline |
Enable the outline tree view feature on server lsp | t |
lsp-dart-outline-position-params |
The outline tree position params. | Left side |
lsp-dart-flutter-outline |
Wheter to enable the Flutter outline tree view feature on server lsp | t |
lsp-dart-flutter-outline-position-params |
The Flutter outline tree position params | Left side |
lsp-dart-flutter-fringe-colors |
Enable the Flutter colors on fringe. | t |
lsp-dart-flutter-widget-guides |
Enable the Flutter widget guide lines from parent to child widgets | t |
lsp-dart-test-code-lens |
Enable the Run code lens on tests. |
t |
lsp-dart-dap-extension-version |
The debugger extension version. | 3.9.1 |
lsp-dart-dap-debugger-path |
The debugger extension path | Check source file |
lsp-dart-dap-dart-debugger-program |
The command to execute the debugger extension on dart projects. | Check source file |
lsp-dart-dap-flutter-debugger-program |
The command to execute the debugger extension on flutter projects. | Check source file |
lsp-dart-dap-debug-external-libraries |
Whether to enable the debug on external libraries | nil |
lsp-dart-dap-debug-sdk-libraries |
Whether to enable the debug on Dart SDK libraries | nil |
lsp-dart-dap-flutter-track-widget-creation |
Whether to pass –track-widget-creation to Flutter apps. Required to support 'Inspect Widget'. | t |
lsp-dart-dap-flutter-structured-errors |
Whether to use Flutter’s structured error support for improve error display. | t |
lsp-dart-dap-flutter-verbose-log |
Whether to enable verbose logs from Flutter DAP | nil |
lsp-dart-dap-devtools-theme |
The devtools theme when openning via lsp-dart-dap-open-devtools |
"dark" |
lsp-dart-dap-devtools-hide-options |
What to hide when openning DevTools via lsp-dart-dap-open-devtools |
debugger |
- lsp-ui : Flycheck, documentation and code actions support.
- lsp-treemacs :
lsp-mode
GUI controls implemented using treemacs. - company-capf : Completion backend support.
- flutter.el : Tool to run emulator from emacs.
- hover.el : Tool to run flutter mobile apps from desktop without the need of an emulator.
❔ Emacs can't find my package, it keeps searching up until the dart root package folder.
🔹 Configure projectile to find the package pubspec.yaml and set the folder as project root:
(with-eval-after-load 'projectile
(add-to-list 'projectile-project-root-files-bottom-up "pubspec.yaml")
(add-to-list 'projectile-project-root-files-bottom-up "BUILD"))
❔ LSP :: No LSP server for dart-mode(check *lsp-log*).
🔹 Try to set the lsp-dart-project-sdk-dir
to the Dart SDK dir instalation or if you are using Flutter, <your-flutter-dir>/bin/cache/dart-sdk/
.
All feedback and suggestions are welcome!
You can open a issue or for a quick anwser, send a message on Gitter.