@@ -89,46 +89,41 @@ Optionally use TEST to compare the hash keys."
8989 h))
9090 h))
9191
92- ; ; TODO: Greatly reduce this complexity
93- (defun lsp-dart-flutter-daemon--process-filter (proc string )
94- " Invoked when a new STRING has arrived from PROC."
92+ (defun lsp-dart-flutter-daemon--process-filter (proc response )
93+ " Invoked when a new RESPONSE has arrived from PROC."
9594 (when (buffer-live-p (process-buffer proc))
9695 (with-current-buffer (process-buffer proc)
97- (let ((should-trim (not (string-match-p (regexp-quote " ][" ) (string-trim string))))
98- (inhibit-read-only t ))
99- (goto-char (process-mark proc))
100- (when (string-prefix-p " [" (string-trim string))
101- (--> string
102- string-trim
103- (replace-regexp-in-string (regexp-quote " },{" ) " }\n {" it nil 'literal )
104- (split-string it " \n " )
105- (-map (lambda (response )
106- (let ((json-message (condition-case-unless-debug oops
107- (lsp--read-json (if should-trim
108- (substring response 1 -1 )
109- response))
110- (error
111- (jsonrpc--warn " Invalid JSON: %S %s %s"
112- oops (buffer-string ) response)
113- nil )))
114- (conn (process-get proc 'jsonrpc-connection )))
115- (when json-message
116- (if (lsp-get json-message :error )
117- (lsp-dart-flutter-daemon--log " ERROR" (lsp-get json-message :error ) (lsp-get json-message :trace )))
118- (if (lsp-get json-message :event )
119- (pcase (lsp-get json-message :event )
120- (" device.removed" (lsp-dart-flutter-daemon--device-removed (lsp-get json-message :params )))
121- (" device.added" (lsp-dart-flutter-daemon--device-added (lsp-get json-message :params )))
122- (" daemon.connected" (lsp-dart-flutter-daemon--send " device.enable" ))
123- (" daemon.logMessage" (lsp-dart-flutter-daemon--log (lsp-get (lsp-get json-message :params ) :level )
124- (lsp-get json-message :params ))))
125- (with-temp-buffer
126- (jsonrpc-connection-receive conn (if lsp-use-plists
127- json-message
128- (lsp-dart-flutter-daemon--hash-table->plist json-message))))))))
129- it)))))))
130-
131- ; ; (lsp-dart-flutter-daemon-get-devices #'identity)
96+ (goto-char (process-mark proc))
97+ (let* ((response (string-trim response))
98+ (should-trim (and (string-prefix-p (regexp-quote " ][" ) response))))
99+ (when (string-prefix-p " [" response)
100+ (-map (lambda (msg )
101+ (let ((json-message (condition-case-unless-debug oops
102+ (lsp--read-json (if should-trim
103+ (substring msg 1 -1 )
104+ msg))
105+ (error
106+ (jsonrpc--warn " Invalid JSON: %S %s %s"
107+ oops (buffer-string ) msg)
108+ nil )))
109+ (conn (process-get proc 'jsonrpc-connection )))
110+ (when-let ((json (if (vectorp json-message)
111+ (aref json-message 0 )
112+ json-message)))
113+ (if (lsp-get json :error )
114+ (lsp-dart-flutter-daemon--log " ERROR" (lsp-get json :error ) (lsp-get json :trace )))
115+ (if (lsp-get json :event )
116+ (pcase (lsp-get json :event )
117+ (" device.removed" (lsp-dart-flutter-daemon--device-removed (lsp-get json :params )))
118+ (" device.added" (lsp-dart-flutter-daemon--device-added (lsp-get json :params )))
119+ (" daemon.connected" (lsp-dart-flutter-daemon--send " device.enable" ))
120+ (" daemon.logMessage" (lsp-dart-flutter-daemon--log (lsp-get (lsp-get json :params ) :level )
121+ (lsp-get (lsp-get json :params ) :message ))))
122+ (with-temp-buffer
123+ (jsonrpc-connection-receive conn (if lsp-use-plists
124+ json
125+ (lsp-dart-flutter-daemon--hash-table->plist json))))))))
126+ (split-string response " \n " )))))))
132127
133128(defun lsp-dart-flutter-daemon--log (level msg &rest args )
134129 " Log for LEVEL, MSG with ARGS adding lsp-dart-flutter-daemon prefix."
@@ -167,13 +162,13 @@ Optionally use TEST to compare the hash keys."
167162OBJ should be a hash-table or plist."
168163 (if lsp-use-plists
169164 (if (or (vectorp obj)
170- (listp obj))
165+ (listp obj))
171166 (-map #'lsp-dart-flutter-daemon--hash-table->plist obj)
172167 (lsp-dart-flutter-daemon--hash-table->plist obj))
173168 (if (or (vectorp obj)
174169 (listp obj))
175- (-map #'lsp-dart-flutter-daemon--plist->hash-table obj)
176- (lsp-dart-flutter-daemon--plist->hash-table obj))))
170+ (-map #'lsp-dart-flutter-daemon--plist->hash-table obj)
171+ (lsp-dart-flutter-daemon--plist->hash-table obj))))
177172
178173(defun lsp-dart-flutter-daemon--send (method &optional params callback )
179174 " Build and send command with METHOD with optional PARAMS.
0 commit comments