@@ -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 )
0 commit comments