Skip to content

Commit 7e436ee

Browse files
authored
Merge pull request #5 from emacs-lsp/add-dap-support
[debug] Add dap-mode support
2 parents 5ae92ae + 48323d5 commit 7e436ee

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ Display the flutter colors on left fringe.
6767

6868
You can disable the feature setting `lsp-dart-fringe-colors` to `nil`.
6969

70+
### Debug
71+
72+
For emacs debugging, `lsp-dart` uses [`dap-mode`](https://github.com/emacs-lsp/dap-mode#dart) to debug.
73+
You only need to run `dap-dart-setup` one time to setup the debugger.
74+
75+
![debug](https://raw.githubusercontent.com/emacs-lsp/lsp-dart/screenshots/debug.gif)
76+
7077
## Supported settings
7178

7279
* `lsp-dart-sdk-dir` - Install directory for dart-sdk.

lsp-dart-dap.el

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
;;; lsp-dart-dap.el --- DAP support for lsp-dart -*- lexical-binding: t; -*-
2+
;;
3+
;; Version: 1.5
4+
;; Keywords: languages, extensions
5+
;; URL: https://github.com/emacs-lsp/lsp-dart.el
6+
;;
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; DAP support for lsp-dart
23+
24+
;;; Code:
25+
26+
(require 'lsp-mode)
27+
(require 'dap-mode)
28+
(require 'dap-utils)
29+
30+
(defcustom lsp-dart-dap--extension-version "3.9.1"
31+
"The extension version."
32+
:group 'lsp-dart-dap
33+
:type 'string)
34+
35+
(defcustom lsp-dart-dap--debugger-path
36+
(expand-file-name "github/Dart-Code.Dart-Code"
37+
dap-utils-extension-path)
38+
"The path to dart vscode extension."
39+
:group 'lsp-dart-dap
40+
:type 'string)
41+
42+
(defcustom lsp-dart-dap-debugger-program
43+
`("node" ,(f-join lsp-dart-dap--debugger-path "extension/out/src/debug/dart_debug_entry.js"))
44+
"The path to the dart debugger."
45+
:group 'lsp-dart-dap
46+
:type '(repeat string))
47+
48+
(defcustom lsp-dart-dap-executable "dart"
49+
"The dart executable from dart SDK dir."
50+
:group 'lsp-dart-dap
51+
:type 'string)
52+
53+
(defun lsp-dart-dap--get-project-root ()
54+
"Return the project root path."
55+
(file-truename (locate-dominating-file default-directory "pubspec.yaml")))
56+
57+
(defun lsp-dart-dap--setup-extension ()
58+
"Setup dart debugger extension to run `lsp-dart-dap-debugger-program`."
59+
(message "DAP Dart :: Setting up...")
60+
(lsp-async-start-process
61+
(lambda ()
62+
(lsp-async-start-process
63+
(lambda () (message "DAP Dart :: Setup done!"))
64+
(lambda () (message "DAP Dart :: Error setting up lsp-dart-dap, check if `npm` is on $PATH"))
65+
(f-join lsp-dart-dap--debugger-path "extension/node_modules/typescript/bin/tsc")
66+
"--project" (f-join lsp-dart-dap--debugger-path "extension")))
67+
(lambda () (message "DAP Dart :: Error setting up lsp-dart-dap, check if `npm` is on $PATH"))
68+
"npm" "install" "--prefix" (f-join lsp-dart-dap--debugger-path "extension")
69+
"--no-package-lock" "--silent" "--no-save"))
70+
71+
(dap-utils-github-extension-setup-function
72+
"dap-dart"
73+
"Dart-Code"
74+
"Dart-Code"
75+
lsp-dart-dap--extension-version
76+
lsp-dart-dap--debugger-path
77+
#'lsp-dart-dap--setup-extension)
78+
79+
(defun lsp-dart-dap--populate-start-file-args (conf)
80+
"Populate CONF with the required arguments."
81+
(-> conf
82+
(dap--put-if-absent :dap-server-path lsp-dart-dap-debugger-program)
83+
(dap--put-if-absent :type "dart")
84+
(dap--put-if-absent :cwd (lsp-dart-dap--get-project-root))
85+
(dap--put-if-absent :program (buffer-file-name))
86+
(dap--put-if-absent :name "Dart Debug")
87+
(dap--put-if-absent :dartPath lsp-dart-dap-executable)
88+
(dap--put-if-absent :debuggerType 0)
89+
(dap--put-if-absent :debugExternalLibraries nil)
90+
(dap--put-if-absent :debugSdkLibraries nil)))
91+
92+
(dap-register-debug-provider "dart" 'lsp-dart-dap--populate-start-file-args)
93+
(dap-register-debug-template "Dart :: Run Configuration"
94+
(list :type "dart"
95+
:cwd nil
96+
:request "launch"
97+
:program nil
98+
:name "Dart::Run"))
99+
100+
(provide 'lsp-dart-dap)
101+
;;; lsp-dart-dap.el ends here

lsp-dart.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;;; lsp-dart.el --- Dart support lsp-mode -*- lexical-binding: t; -*-
22

33
;; Version: 1.0
4-
;; Package-Requires: ((emacs "25.2") (lsp-treemacs "0.1") (lsp-mode "6.0") (ht "2.0") (f "0.20.0") (dash "2.14.1") (dart-mode "1.0.5"))
4+
;; Package-Requires: ((emacs "25.2") (lsp-treemacs "0.1") (lsp-mode "6.0") (dap-mode "0.3") (ht "2.0") (f "0.20.0") (dash "2.14.1") (dart-mode "1.0.5"))
55
;; Keywords: languages, extensions
66
;; URL: https://github.com/emacs-lsp/lsp-dart.el
77

@@ -31,6 +31,7 @@
3131
(require 'lsp-mode)
3232

3333
(require 'lsp-dart-fringe)
34+
(require 'lsp-dart-dap)
3435

3536
(defconst lsp-dart-tests-buffer-name "*LSP Dart tests*")
3637

0 commit comments

Comments
 (0)