2121
2222(require 'comint )
2323(require 'dash )
24- (require 'ht )
2524(require 'lsp-mode )
2625
26+ (require 'lsp-dart-protocol )
2727(require 'lsp-dart-utils )
2828
2929(defconst lsp-dart-flutter-daemon-buffer-name " *LSP Dart - Flutter daemon*" )
6666(defun lsp-dart-flutter-daemon--build-command (id method &optional params )
6767 " Build a command from an ID and METHOD.
6868PARAMS is the optional method params."
69- (let ((command (ht ( " id " id)
70- ( " method" method) )))
69+ (let ((command (lsp-make-flutter-daemon-command :id id
70+ : method method)))
7171 (when params
72- (ht- set! command " params" params))
72+ (lsp: set-flutter-daemon- command- params? command params))
7373 (concat " ["
7474 (lsp--json-serialize command)
7575 " ]\n " )))
@@ -86,22 +86,23 @@ PARAMS is the optional method params."
8686
8787(defun lsp-dart-flutter-daemon--handle-responses (raw-response )
8888 " Handle Flutter daemon response from RAW-RESPONSE."
89- (-map (-lambda ((&hash " id" " event" " result" " params" (params &as &hash? " level" " message" )))
90- (if event
91- (pcase event
89+ (-map (-lambda ((&FlutterDaemonResponse :id :event? :result?
90+ :params? (params &as &FlutterDaemonResponseParams? :level? :message? )))
91+ (if event?
92+ (pcase event?
9293 (" device.removed" (lsp-dart-flutter-daemon--device-removed params))
9394
9495 (" device.added" (lsp-dart-flutter-daemon--device-added params))
9596
96- (" daemon.logMessage" (lsp-dart-flutter-daemon--log level message)))
97+ (" daemon.logMessage" (lsp-dart-flutter-daemon--log level? message? ) ))
9798 (let* ((command (alist-get id lsp-dart-flutter-daemon-commands))
98- (callback (gethash " callback " command)))
99+ (callback (plist-get command :callback )))
99100 (when command
100101 (setq lsp-dart-flutter-daemon-commands
101102 (lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-commands)))
102103 (when callback
103- (when result
104- (funcall callback result))))))
104+ (when result?
105+ (funcall callback result? ) )))))
105106 (lsp-dart-flutter-daemon--raw->response raw-response)))
106107
107108(defun lsp-dart-flutter-daemon--send (method &optional params callback )
@@ -112,7 +113,7 @@ of this command."
112113 (lsp-dart-flutter-daemon-start))
113114 (let* ((id (lsp-dart-flutter-daemon--generate-command-id))
114115 (command (lsp-dart-flutter-daemon--build-command id method params)))
115- (add-to-list 'lsp-dart-flutter-daemon-commands (cons id (ht ( " callback" callback) )))
116+ (add-to-list 'lsp-dart-flutter-daemon-commands (cons id (list : callback callback)))
116117 (comint-send-string (get-buffer-process lsp-dart-flutter-daemon-buffer-name) command)))
117118
118119(defun lsp-dart-flutter-daemon--device-removed (device )
@@ -121,18 +122,17 @@ of this command."
121122 (lsp-dart-remove-from-alist it lsp-dart-flutter-daemon-devices)
122123 (setq lsp-dart-flutter-daemon-devices it)))
123124
124- (defun lsp-dart-flutter-daemon--device-added (device )
125+ (lsp- defun lsp-dart-flutter-daemon--device-added (( device &as &FlutterDaemonDevice :id ) )
125126 " 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 )
127+ (-let ((device-to-add (cons id device)))
128+ (lsp:set-flutter-daemon-device-is-device? device t )
129129 (setq lsp-dart-flutter-daemon-devices
130130 (lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-devices))
131131 (add-to-list 'lsp-dart-flutter-daemon-devices device-to-add)
132132 (-when-let (listener (alist-get id lsp-dart-flutter-daemon-device-added-listeners))
133133 (setq lsp-dart-flutter-daemon-device-added-listeners
134134 (lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-device-added-listeners))
135- (funcall (gethash " callback " listener) device))))
135+ (funcall (plist-get listener :callback ) device))))
136136
137137(defun lsp-dart-flutter-daemon-get-devices (callback )
138138 " Call CALLBACK with the available emulators and devices from Flutter daemon."
@@ -145,18 +145,17 @@ of this command."
145145 (append emulators)
146146 (funcall callback)))))
147147
148- (defun lsp-dart-flutter-daemon-launch (emulator callback )
149- " Launch EMULATOR and wait for connected state and call CALLBACK."
148+ (lsp- defun lsp-dart-flutter-daemon-launch ((device &as &FlutterDaemonDevice :id :is-device? ) callback)
149+ " Launch DEVICE and wait for connected state and call CALLBACK."
150150 (if lsp-dart-flutter-daemon-current-device
151151 (funcall callback lsp-dart-flutter-daemon-current-device)
152152 (progn
153- (setq lsp-dart-flutter-daemon-current-device emulator)
154- (if (gethash " is-device" emulator)
155- (funcall callback emulator)
156- (-let* (((&hash " id" ) emulator)
157- (params (ht (" emulatorId" id))))
153+ (setq lsp-dart-flutter-daemon-current-device device)
154+ (if is-device?
155+ (funcall callback device)
156+ (-let* ((params (lsp-make-flutter-daemon-emulator-launch :emulator-id id)))
158157 (add-to-list 'lsp-dart-flutter-daemon-device-added-listeners
159- (cons id (ht ( " callback" callback) )))
158+ (cons id (list : callback callback)))
160159 (lsp-dart-flutter-daemon--send " emulator.launch" params callback))))))
161160
162161(defun lsp-dart-flutter-daemon--reset-current-device (_session )
0 commit comments