-
-
Notifications
You must be signed in to change notification settings - Fork 2
Analysis of your code is now provided via the Language Server Protocol
(as well as the dart_language_server
, and dartanalyzer
).
There are currently two packages that provide this feature in Emacs,
eglot
(Emacs Polyglot) and lsp-mode
.
project.el
is currently used by both eglot
and lsp-mode
.
The following snippet assists project.el
in finding the project root
for your dart file.
(defun project-try-dart (dir)
(let ((project (or (locate-dominating-file dir "pubspec.yaml")
(locate-dominating-file dir "BUILD"))))
(if project
(cons 'dart project)
(cons 'transient dir))))
(add-hook 'project-find-functions #'project-try-dart)
(cl-defmethod project-roots ((project (head dart)))
(list (cdr project)))
Requires emacs-major-version
at least 26.
Install https://github.com/joaotavora/eglot.
(add-to-list 'eglot-server-programs '(dart-mode . ("dart_language_server")))
Try M-x eglot RET
, or add a hook.
(add-hook 'dart-mode-hook 'eglot-ensure)
Install https://github.com/emacs-lsp/lsp-mode.
Try M-x lsp RET
, or add a hook.
(add-hook 'dart-mode-hook 'lsp)
From https://github.com/emacs-lsp/lsp-mode/issues/576.
Help lsp-mode
find your project root automatically.
(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"))
(setq lsp-auto-guess-root t)
We no longer recommend (setq dart-enable-analysis-server t)
.
There is still a section of code in dart-mode.el
that starts with
;;; Dart analysis server
Unfortunately, a number of issues have been arising with it, and the dart-mode project is not keeping up with them. We may in the future, but for now, consider it wontfix, or deprecated, or consider eglot or lsp-mode as workarounds. We might split that section out into another file or even repo at some point. Issues with the server are still welcome as informational, but they may be labelled and closed indefinitely to keep the issue tracker organized.
The previous_README is archived here, and still has the information about setting up the builtin support for the Dart analysis server.