|
42 | 42 | :group 'lsp-dart |
43 | 43 | :type 'string) |
44 | 44 |
|
45 | | -(defcustom lsp-dart-dap-debugger-program |
| 45 | +(defcustom lsp-dart-dap-dart-debugger-program |
46 | 46 | `("node" ,(f-join lsp-dart-dap-debugger-path "extension/out/src/debug/dart_debug_entry.js")) |
47 | 47 | "The path to the dart debugger." |
48 | 48 | :group 'lsp-dart |
49 | 49 | :type '(repeat string)) |
50 | 50 |
|
| 51 | +(defcustom lsp-dart-dap-flutter-debugger-program |
| 52 | + `("node" ,(f-join lsp-dart-dap-debugger-path "extension/out/src/debug/flutter_debug_entry.js")) |
| 53 | + "The path to the Flutter debugger." |
| 54 | + :group 'lsp-dart |
| 55 | + :type '(repeat string)) |
| 56 | + |
| 57 | +(defcustom lsp-dart-dap-debug-external-libraries nil |
| 58 | + "If non-nil, enable the debug on external libraries." |
| 59 | + :group 'lsp-dart |
| 60 | + :type 'boolean) |
| 61 | + |
| 62 | +(defcustom lsp-dart-dap-debug-sdk-libraries nil |
| 63 | + "If non-nil, enable the debug on Dart SDK libraries." |
| 64 | + :group 'lsp-dart |
| 65 | + :type 'boolean) |
| 66 | + |
51 | 67 | (defcustom lsp-dart-dap-devtools-theme "dark" |
52 | 68 | "The theme to Dart DevTools." |
53 | 69 | :group 'lsp-dart |
|
58 | 74 | :group 'lsp-dart |
59 | 75 | :type 'string) |
60 | 76 |
|
| 77 | +(defcustom lsp-dart-dap-flutter-track-widget-creation t |
| 78 | + "Whether to pass –track-widget-creation to Flutter apps. |
| 79 | +Required to support 'Inspect Widget'." |
| 80 | + :group 'lsp-dart |
| 81 | + :type 'string) |
| 82 | + |
| 83 | +(defcustom lsp-dart-dap-flutter-structured-errors t |
| 84 | + "Whether to use Flutter's structured error support for improve error display." |
| 85 | + :group 'lsp-dart |
| 86 | + :type 'string) |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +;;; Internal |
| 91 | + |
61 | 92 | (defconst lsp-dart-dap--devtools-buffer-name "*LSP Dart - DevTools*") |
62 | 93 | (defconst lsp-dart-dap--pub-list-pacakges-buffer-name "*LSP Dart - Pub list packages*") |
63 | 94 |
|
64 | 95 | (defun lsp-dart-dap--setup-extension () |
65 | | - "Setup dart debugger extension to run `lsp-dart-dap-debugger-program`." |
| 96 | + "Setup dart debugger extension to run `lsp-dart-dap-dart-debugger-program`." |
66 | 97 | (lsp-dart-project-log "Setting up DAP...") |
67 | 98 | (lsp-async-start-process |
68 | 99 | (lambda () |
|
83 | 114 | lsp-dart-dap-debugger-path |
84 | 115 | #'lsp-dart-dap--setup-extension) |
85 | 116 |
|
86 | | -(defun lsp-dart-dap--populate-start-file-args (conf) |
87 | | - "Populate CONF with the required arguments." |
| 117 | +(defun lsp-dart-dap--populate-dart-start-file-args (conf) |
| 118 | + "Populate CONF with the required arguments for dart debug." |
88 | 119 | (-> conf |
89 | | - (dap--put-if-absent :dap-server-path lsp-dart-dap-debugger-program) |
90 | | - (dap--put-if-absent :type "dart") |
| 120 | + (dap--put-if-absent :dap-server-path lsp-dart-dap-dart-debugger-program) |
91 | 121 | (dap--put-if-absent :cwd (lsp-dart-project-get-root)) |
92 | 122 | (dap--put-if-absent :program (buffer-file-name)) |
93 | | - (dap--put-if-absent :name "Dart Debug") |
94 | 123 | (dap--put-if-absent :dartPath (lsp-dart-project-dart-command)) |
95 | | - (dap--put-if-absent :debuggerType 0) |
96 | | - (dap--put-if-absent :debugExternalLibraries nil) |
97 | | - (dap--put-if-absent :debugSdkLibraries nil))) |
| 124 | + (dap--put-if-absent :debugExternalLibraries lsp-dart-dap-debug-external-libraries) |
| 125 | + (dap--put-if-absent :debugSdkLibraries lsp-dart-dap-debug-sdk-libraries))) |
98 | 126 |
|
99 | | -(dap-register-debug-provider "dart" 'lsp-dart-dap--populate-start-file-args) |
100 | | -(dap-register-debug-template "Dart :: Run Configuration" |
| 127 | +(dap-register-debug-provider "dart" 'lsp-dart-dap--populate-dart-start-file-args) |
| 128 | +(dap-register-debug-template "Dart :: Debug" |
101 | 129 | (list :type "dart" |
102 | | - :cwd nil |
103 | 130 | :request "launch" |
104 | | - :program nil |
105 | | - :name "Dart::Run")) |
| 131 | + :name "Dart")) |
| 132 | + |
| 133 | +;; Flutter |
| 134 | + |
| 135 | +(defun lsp-dart-dap--flutter-get-or-create-device () |
| 136 | + "Return the device to debug or prompt to start it." |
| 137 | + (ht ('id "emulator-5554") |
| 138 | + ('name "device"))) |
| 139 | + |
| 140 | +(defun lsp-dart-dap--populate-flutter-start-file-args (conf) |
| 141 | + "Populate CONF with the required arguments for Flutter debug." |
| 142 | + (-let* ((root (lsp-dart-project-get-root)) |
| 143 | + ((&hash "id" device-id "name" device-name) (lsp-dart-dap--flutter-get-or-create-device))) |
| 144 | + (-> conf |
| 145 | + (dap--put-if-absent :dap-server-path lsp-dart-dap-flutter-debugger-program) |
| 146 | + (dap--put-if-absent :cwd root) |
| 147 | + (dap--put-if-absent :program (lsp-dart-project-get-entrypoint)) |
| 148 | + (dap--put-if-absent :dartPath (lsp-dart-project-dart-command)) |
| 149 | + (dap--put-if-absent :flutterPath (lsp-dart-project-get-flutter-path)) |
| 150 | + (dap--put-if-absent :flutterTrackWidgetCreation lsp-dart-dap-flutter-track-widget-creation) |
| 151 | + (dap--put-if-absent :useFlutterStructuredErrors lsp-dart-dap-flutter-structured-errors) |
| 152 | + (dap--put-if-absent :debugExternalLibraries lsp-dart-dap-debug-external-libraries) |
| 153 | + (dap--put-if-absent :debugSdkLibraries lsp-dart-dap-debug-sdk-libraries) |
| 154 | + (dap--put-if-absent :deviceId device-id) |
| 155 | + (dap--put-if-absent :deviceName device-name) |
| 156 | + (dap--put-if-absent :name (concat "Flutter (" device-name ")"))))) |
| 157 | + |
| 158 | +(dap-register-debug-provider "flutter" 'lsp-dart-dap--populate-flutter-start-file-args) |
| 159 | +(dap-register-debug-template "Flutter :: Debug" |
| 160 | + (list :type "flutter" |
| 161 | + :request "launch" |
| 162 | + :flutterMode "debug" |
| 163 | + :flutterPlatform "default" |
| 164 | + :name "Flutter")) |
| 165 | + |
| 166 | +;; DevTools |
106 | 167 |
|
107 | 168 | (cl-defmethod dap-handle-event ((_event (eql dart.debuggerUris)) _session params) |
108 | 169 | "Handle debugger uris EVENT for SESSION with PARAMS." |
@@ -202,6 +263,9 @@ If it is already activated or after activated successfully, call CALLBACK." |
202 | 263 | (url (concat "http://" uri "?" params))) |
203 | 264 | (browse-url url))) |
204 | 265 |
|
| 266 | + |
| 267 | +;;; Public interface |
| 268 | + |
205 | 269 | ;;;###autoload |
206 | 270 | (defun lsp-dart-dap-open-devtools () |
207 | 271 | "Open Dart DevTools for the current debug session." |
|
0 commit comments