Skip to content

Commit 78a6c3e

Browse files
committed
Fix some dart commands not working after dart sdk 2.16.0
1 parent c2f3cad commit 78a6c3e

File tree

7 files changed

+37
-27
lines changed

7 files changed

+37
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix duplicated logs on old debugger. #154
77
* Fix `lsp-dart-run` for dart only files. #168
88
* Fix test tree when debugging dart/flutter tests.
9+
* Fix some dart commands not working after dart sdk 2.16.0.
910

1011
## 1.22.0
1112

lsp-dart-commands.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(defun lsp-dart--run-command (command args)
2929
"Run COMMAND with ARGS from the project root."
3030
(lsp-dart-from-project-root
31-
(compilation-start (format "%s %s" command args)
31+
(compilation-start (format "%s %s" (string-join command " ") args)
3232
t
3333
(lambda (_) lsp-dart-commands-buffer-name))))
3434

lsp-dart-dap.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Call CALLBACK when the device is chosen and started successfully."
261261
(dap--put-if-absent :deviceId device-id)
262262
(dap--put-if-absent :deviceName device-name)
263263
(dap--put-if-absent :dap-server-path (if (lsp-dart-dap-use-sdk-debugger-p)
264-
`(,(lsp-dart-flutter-command) "debug_adapter" "-d" ,device-id)
264+
(append (lsp-dart-flutter-command) (list "debug_adapter" "-d" device-id))
265265
lsp-dart-dap-flutter-debugger-program))
266266
(dap--put-if-absent :flutterPlatform "default")
267267
(dap--put-if-absent :toolArgs `("-d" ,device-id))
@@ -453,7 +453,7 @@ Run program PATH if not nil passing ARGS if not nil."
453453
(-> (list :name "Flutter Tests"
454454
:type "flutter"
455455
:dap-server-path (if (lsp-dart-dap-use-sdk-debugger-p)
456-
`(,(lsp-dart-flutter-command) "debug_adapter" "--test")
456+
(append (lsp-dart-flutter-command) '("debug_adapter" "--test"))
457457
lsp-dart-dap-flutter-test-debugger-program)
458458
:program path
459459
:noDebug nil

lsp-dart-flutter-daemon.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
(defun lsp-dart-flutter-daemon-start ()
5454
"Start the Flutter daemon."
5555
(unless (lsp-dart-flutter-daemon--running-p)
56-
(let ((buffer (get-buffer-create lsp-dart-flutter-daemon-buffer-name)))
57-
(make-comint-in-buffer lsp-dart-flutter-daemon-name buffer (lsp-dart-flutter-command) nil "daemon")
56+
(let ((buffer (get-buffer-create lsp-dart-flutter-daemon-buffer-name))
57+
(command (lsp-dart-flutter-command)))
58+
(make-comint-in-buffer lsp-dart-flutter-daemon-name buffer (car command) nil (append (cdr command) '("daemon")))
5859
(with-current-buffer buffer
5960
(unless (derived-mode-p 'lsp-dart-flutter-daemon-mode)
6061
(lsp-dart-flutter-daemon-mode))
@@ -167,7 +168,7 @@ of this command."
167168
"Major mode for `lsp-dart-flutter-daemon-start`."
168169
(setq comint-prompt-read-only nil)
169170
(setq comint-process-echoes nil)
170-
(setenv "PATH" (concat (lsp-dart-flutter-command) ":" (getenv "PATH"))))
171+
(setenv "PATH" (concat (car (lsp-dart-flutter-command)) ":" (getenv "PATH"))))
171172

172173
(provide 'lsp-dart-flutter-daemon)
173174
;;; lsp-dart-flutter-daemon.el ends here

lsp-dart-test-support.el

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ NOTIFICATION is the event notification.")
123123
"Handle testStart NOTIFICATION."
124124
(-let (((&TestStartNotification :time :test (&Test :id :name?)) notification))
125125
(lsp-dart-test--set-running-test id (make-lsp-dart-running-test :id id
126-
:name name?
127-
:start-time time))
126+
:name name?
127+
:start-time time))
128128
(run-hook-with-args 'lsp-dart-test-start-notification-hook notification)))
129129

130130
(cl-defmethod lsp-dart-test--handle-notification ((_event (eql allSuites)) _notification)
@@ -186,7 +186,7 @@ NOTIFICATION is the event notification.")
186186
(setq-local default-directory (or project-rt default-directory))
187187
(unless (derived-mode-p 'lsp-dart-test-process-mode)
188188
(lsp-dart-test-process-mode))
189-
(apply #'make-comint-in-buffer lsp-dart-test--process-buffer-name process-buffer command nil args))))
189+
(apply #'make-comint-in-buffer lsp-dart-test--process-buffer-name process-buffer (car command) nil (append (cdr command) args)))))
190190

191191
(defun lsp-dart-test--run (&optional test)
192192
"Run Dart/Flutter test command in a compilation buffer.
@@ -211,7 +211,7 @@ to run otherwise run all tests from file-name in TEST."
211211
(lsp-dart-assoc-if test-arg "--name")
212212
(lsp-dart-assoc-if test-arg test-arg)
213213
(append (list test-file)))))
214-
(lsp-dart-test--run-process (lsp-dart-test--build-command) (lsp-dart-test--build-command-extra-args)))
214+
(lsp-dart-test--run-process (lsp-dart-test--build-command) (lsp-dart-test--build-command-extra-args)))
215215
(run-hooks 'lsp-dart-test-run-started-hook))
216216

217217
(defun lsp-dart-test--debug (test)
@@ -362,8 +362,8 @@ NAMES arg is optional and are the group of tests representing a test name."
362362
(setq comint-process-echoes nil)
363363
(setq process-connection-type nil)
364364
(if (lsp-dart-flutter-project-p)
365-
(setenv "PATH" (concat (lsp-dart-flutter-command) ":" (getenv "PATH")))
366-
(setenv "PATH" (concat (lsp-dart-pub-command) ":" (getenv "PATH"))))
365+
(setenv "PATH" (concat (car (lsp-dart-flutter-command)) ":" (getenv "PATH")))
366+
(setenv "PATH" (concat (car (lsp-dart-pub-command)) ":" (getenv "PATH"))))
367367
(setq-local comint-output-filter-functions #'lsp-dart-test--handle-process-response))
368368

369369
(define-minor-mode lsp-dart-test-mode

lsp-dart-utils.el

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ FLUTTER_ROOT environment variable."
135135
file-truename)
136136
(getenv "FLUTTER_ROOT")))
137137

138-
(defun lsp-dart-pub-command ()
139-
"Return the pub executable path from Dart SDK path."
140-
(if (eq system-type 'windows-nt)
141-
(expand-file-name "bin/pub.bat" (lsp-dart-get-sdk-dir)))
142-
(expand-file-name "bin/pub" (lsp-dart-get-sdk-dir)))
143-
144-
(defun lsp-dart-pub-snapshot-command ()
145-
"Return the pub snapshot executable path from Dart SDK path."
146-
(expand-file-name "bin/snapshots/pub.dart.snapshot" (lsp-dart-get-sdk-dir)))
147-
148138
(defun lsp-dart-dart-command ()
149139
"Return the dart executable from Dart SDK dir."
150140
(let* ((executable-path (if (eq system-type 'windows-nt) "bin/dart.bat" "bin/dart"))
@@ -153,14 +143,26 @@ FLUTTER_ROOT environment variable."
153143
command
154144
(lsp-dart-log "Dart command not found in path '%s'" command))))
155145

146+
(defun lsp-dart-pub-command ()
147+
"Return the pub executable path from Dart SDK path."
148+
(if (lsp-dart-version-at-least-p "2.16.0")
149+
(list (lsp-dart-dart-command) "pub")
150+
(if (eq system-type 'windows-nt)
151+
(list (expand-file-name "bin/pub.bat" (lsp-dart-get-sdk-dir)))
152+
(list (expand-file-name "bin/pub" (lsp-dart-get-sdk-dir))))))
153+
154+
(defun lsp-dart-pub-snapshot-command ()
155+
"Return the pub snapshot executable path from Dart SDK path."
156+
(expand-file-name "bin/snapshots/pub.dart.snapshot" (lsp-dart-get-sdk-dir)))
157+
156158
(defun lsp-dart-flutter-command ()
157159
"Return the flutter executable from Flutter SDK dir."
158160
(let* ((executable-path (if (eq system-type 'windows-nt)
159161
"bin/flutter.bat"
160162
(concat "bin/" lsp-dart-flutter-executable)))
161163
(command (expand-file-name executable-path (lsp-dart-get-flutter-sdk-dir))))
162164
(if (file-exists-p command)
163-
command
165+
(list command)
164166
(lsp-dart-log "Flutter command not found in path '%s'" command))))
165167

166168

@@ -229,7 +231,7 @@ FLUTTER_ROOT environment variable."
229231

230232
(defun lsp-dart-get-full-flutter-version ()
231233
"Retrieve the Flutter version from shell command."
232-
(->> (concat (lsp-dart-flutter-command) " --version")
234+
(->> (concat (string-join (lsp-dart-flutter-command) " ") " --version")
233235
shell-command-to-string))
234236

235237
(defun lsp-dart-get-dart-version ()

test/lsp-dart-utils-test.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@
105105
(mock (getenv "FLUTTER_ROOT") => "/flutter/sdk")
106106
(should (equal (lsp-dart-get-flutter-sdk-dir) "/flutter/sdk"))))
107107

108-
(ert-deftest lsp-dart-pub-command--test ()
108+
(ert-deftest lsp-dart-pub-command--old-version-test ()
109109
(lsp-dart-test-with-dart-sdk
110-
(should (equal (lsp-dart-pub-command) (f-expand "bin/pub" dart-sdk)))))
110+
(mock (lsp-dart-get-dart-version) => "2.15.5")
111+
(should (equal (lsp-dart-pub-command) (list (f-expand "bin/pub" dart-sdk))))))
112+
113+
(ert-deftest lsp-dart-pub-command--new-version-test ()
114+
(lsp-dart-test-with-dart-sdk
115+
(mock (lsp-dart-get-dart-version) => "2.16.0")
116+
(should (equal (lsp-dart-pub-command) (list (f-expand "bin/dart" dart-sdk) "pub")))))
111117

112118
(ert-deftest lsp-dart-pub-snapshot-command--test ()
113119
(lsp-dart-test-with-dart-sdk
@@ -119,7 +125,7 @@
119125

120126
(ert-deftest lsp-dart-flutter-command--test ()
121127
(lsp-dart-test-with-flutter-sdk
122-
(should (equal (lsp-dart-flutter-command) (f-expand (if (eq system-type 'windows-nt) "bin/flutter.bat" "bin/flutter") flutter-sdk)))))
128+
(should (equal (lsp-dart-flutter-command) (list (f-expand (if (eq system-type 'windows-nt) "bin/flutter.bat" "bin/flutter") flutter-sdk))))))
123129

124130
(ert-deftest lsp-dart-get-project-root--test ()
125131
(lsp-dart-test-from-dart-project

0 commit comments

Comments
 (0)