21
21
22
22
(require 'comint )
23
23
(require 'dash )
24
- (require 'ht )
25
24
(require 'lsp-mode )
26
25
26
+ (require 'lsp-dart-protocol )
27
27
(require 'lsp-dart-utils )
28
28
29
29
(defconst lsp-dart-flutter-daemon-buffer-name " *LSP Dart - Flutter daemon*" )
66
66
(defun lsp-dart-flutter-daemon--build-command (id method &optional params )
67
67
" Build a command from an ID and METHOD.
68
68
PARAMS 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)))
71
71
(when params
72
- (ht- set! command " params" params))
72
+ (lsp: set-flutter-daemon- command- params? command params))
73
73
(concat " ["
74
74
(lsp--json-serialize command)
75
75
" ]\n " )))
@@ -86,22 +86,23 @@ PARAMS is the optional method params."
86
86
87
87
(defun lsp-dart-flutter-daemon--handle-responses (raw-response )
88
88
" 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?
92
93
(" device.removed" (lsp-dart-flutter-daemon--device-removed params))
93
94
94
95
(" device.added" (lsp-dart-flutter-daemon--device-added params))
95
96
96
- (" daemon.logMessage" (lsp-dart-flutter-daemon--log level message)))
97
+ (" daemon.logMessage" (lsp-dart-flutter-daemon--log level? message? ) ))
97
98
(let* ((command (alist-get id lsp-dart-flutter-daemon-commands))
98
- (callback (gethash " callback " command)))
99
+ (callback (plist-get command :callback )))
99
100
(when command
100
101
(setq lsp-dart-flutter-daemon-commands
101
102
(lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-commands)))
102
103
(when callback
103
- (when result
104
- (funcall callback result))))))
104
+ (when result?
105
+ (funcall callback result? ) )))))
105
106
(lsp-dart-flutter-daemon--raw->response raw-response)))
106
107
107
108
(defun lsp-dart-flutter-daemon--send (method &optional params callback )
@@ -112,7 +113,7 @@ of this command."
112
113
(lsp-dart-flutter-daemon-start))
113
114
(let* ((id (lsp-dart-flutter-daemon--generate-command-id))
114
115
(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)))
116
117
(comint-send-string (get-buffer-process lsp-dart-flutter-daemon-buffer-name) command)))
117
118
118
119
(defun lsp-dart-flutter-daemon--device-removed (device )
@@ -121,18 +122,17 @@ of this command."
121
122
(lsp-dart-remove-from-alist it lsp-dart-flutter-daemon-devices)
122
123
(setq lsp-dart-flutter-daemon-devices it)))
123
124
124
- (defun lsp-dart-flutter-daemon--device-added (device )
125
+ (lsp- defun lsp-dart-flutter-daemon--device-added (( device &as &FlutterDaemonDevice :id ) )
125
126
" 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 )
129
129
(setq lsp-dart-flutter-daemon-devices
130
130
(lsp-dart-remove-from-alist id lsp-dart-flutter-daemon-devices))
131
131
(add-to-list 'lsp-dart-flutter-daemon-devices device-to-add)
132
132
(-when-let (listener (alist-get id lsp-dart-flutter-daemon-device-added-listeners))
133
133
(setq lsp-dart-flutter-daemon-device-added-listeners
134
134
(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))))
136
136
137
137
(defun lsp-dart-flutter-daemon-get-devices (callback )
138
138
" Call CALLBACK with the available emulators and devices from Flutter daemon."
@@ -145,18 +145,17 @@ of this command."
145
145
(append emulators)
146
146
(funcall callback)))))
147
147
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."
150
150
(if lsp-dart-flutter-daemon-current-device
151
151
(funcall callback lsp-dart-flutter-daemon-current-device)
152
152
(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)))
158
157
(add-to-list 'lsp-dart-flutter-daemon-device-added-listeners
159
- (cons id (ht ( " callback" callback) )))
158
+ (cons id (list : callback callback)))
160
159
(lsp-dart-flutter-daemon--send " emulator.launch" params callback))))))
161
160
162
161
(defun lsp-dart-flutter-daemon--reset-current-device (_session )
0 commit comments