Skip to content

Commit dd3720d

Browse files
committed
Fix macro expanding
1 parent 2637c1d commit dd3720d

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

lsp-dart-flutter-daemon.el

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,6 @@ PARAMS is the optional method params."
7474
(lsp--json-serialize command)
7575
"]\n")))
7676

77-
(defun lsp-dart-flutter-daemon--device-added (device)
78-
"Add DEVICE to the devices list."
79-
(-let (((&hash "id") device))
80-
(ht-set! device "is-device" t)
81-
(setf (alist-get id lsp-dart-flutter-daemon-devices nil t #'string=) nil)
82-
(add-to-list 'lsp-dart-flutter-daemon-devices (cons (gethash "id" device) device))
83-
(when-let (listener (alist-get id lsp-dart-flutter-daemon-device-added-listeners))
84-
(setf (alist-get id lsp-dart-flutter-daemon-device-added-listeners nil t #'string=) nil)
85-
(funcall (gethash "callback" listener) device))))
86-
87-
(defun lsp-dart-flutter-daemon--device-removed (device)
88-
"Remove DEVICE from the devices list."
89-
(-> (gethash "id" device)
90-
(alist-get lsp-dart-flutter-daemon-devices nil t 'string=)
91-
(setf nil)))
92-
9377
(defun lsp-dart-flutter-daemon--raw->response (response)
9478
"Parse raw RESPONSE into a list of responses."
9579
(when (string-prefix-p "[" (string-trim response))
@@ -113,7 +97,8 @@ PARAMS is the optional method params."
11397
(let* ((command (alist-get id lsp-dart-flutter-daemon-commands))
11498
(callback (gethash "callback" command)))
11599
(when command
116-
(setf (alist-get id lsp-dart-flutter-daemon-commands nil t) nil))
100+
(setq lsp-dart-flutter-daemon-commands
101+
(lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-commands)))
117102
(when callback
118103
(when result
119104
(funcall callback result))))))
@@ -127,9 +112,28 @@ of this command."
127112
(lsp-dart-flutter-daemon-start))
128113
(let* ((id (lsp-dart-flutter-daemon--generate-command-id))
129114
(command (lsp-dart-flutter-daemon--build-command id method params)))
130-
(add-to-list 'lsp-dart-flutter-daemon-commands `(,id . ,(ht ("callback" callback))))
115+
(add-to-list 'lsp-dart-flutter-daemon-commands (cons id (ht ("callback" callback))))
131116
(comint-send-string (get-buffer-process lsp-dart-flutter-daemon-buffer-name) command)))
132117

118+
(defun lsp-dart-flutter-daemon--device-removed (device)
119+
"Remove DEVICE from the devices list."
120+
(--> (gethash "id" device)
121+
(lsp-dart-remove-from-alist it lsp-dart-flutter-daemon-devices)
122+
(setq lsp-dart-flutter-daemon-devices it)))
123+
124+
(defun lsp-dart-flutter-daemon--device-added (device)
125+
"Add DEVICE to the devices list."
126+
(-let* ((id (gethash "id" device))
127+
(device-to-add (cons id device)))
128+
(ht-set! device "is-device" t)
129+
(setq lsp-dart-flutter-daemon-devices
130+
(lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-devices))
131+
(add-to-list 'lsp-dart-flutter-daemon-devices device-to-add)
132+
(-when-let (listener (alist-get id lsp-dart-flutter-daemon-device-added-listeners))
133+
(setq lsp-dart-flutter-daemon-device-added-listeners
134+
(lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-device-added-listeners))
135+
(funcall (gethash "callback" listener) device))))
136+
133137
(defun lsp-dart-flutter-daemon-get-devices (callback)
134138
"Call CALLBACK with the available emulators and devices from Flutter daemon."
135139
(lsp-dart-flutter-daemon--send
@@ -152,7 +156,7 @@ of this command."
152156
(-let* (((&hash "id") emulator)
153157
(params (ht ("emulatorId" id))))
154158
(add-to-list 'lsp-dart-flutter-daemon-device-added-listeners
155-
`(,id . ,(ht ("callback" callback))))
159+
(cons id (ht ("callback" callback))))
156160
(lsp-dart-flutter-daemon--send "emulator.launch" params callback))))))
157161

158162
(defun lsp-dart-flutter-daemon--reset-current-device (_session)

lsp-dart-utils.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ FLUTTER_ROOT environment variable and the PATH environment variable."
5353
(defun lsp-dart--flutter-project-p ()
5454
"Return non-nil if buffer is a flutter project."
5555
(or (lsp-dart--flutter-repo-p)
56-
(when-let (pubspec-path (-some->> (lsp-dart-get-project-root)
57-
(expand-file-name "pubspec.yaml")))
56+
(-when-let (pubspec-path (-some->> (lsp-dart-get-project-root)
57+
(expand-file-name "pubspec.yaml")))
5858
(with-temp-buffer
5959
(insert-file-contents pubspec-path)
6060
(goto-char (point-min))
6161
(re-search-forward "sdk\s*:\s*flutter" nil t)))))
6262

63+
(defun lsp-dart-remove-from-alist (key alist)
64+
"Remove item with KEY from ALIST."
65+
(delq (assoc key alist) alist))
66+
6367

6468
;; SDKs
6569

0 commit comments

Comments
 (0)