Skip to content

Commit

Permalink
avoid Illegal :UTF-8 character starting at position ... error
Browse files Browse the repository at this point in the history
There are cases where typescript-language-server returns output that cannot be parsed as utf-8.

```
"sortText":"ï¿¿12\u0000msTextAutospace\u0000"
```

To avoid this problem, we will process the data as a byte string rather than a string.
  • Loading branch information
cxxxr committed Sep 20, 2024
1 parent 9690530 commit 7db34da
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/async-process.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
(process :pointer)
(string :string))

(cffi:defcfun ("process_receive_output" %process-receive-output) :string
(cffi:defcfun ("process_receive_output" %process-receive-output) :pointer
(process :pointer))

(cffi:defcfun ("process_alive_p" %process-alive-p) :boolean
Expand Down Expand Up @@ -93,9 +93,16 @@
(let ((cffi:*default-foreign-encoding* (process-encode process)))
(%process-send-input (process-process process) string)))

(defun pointer-to-string (pointer)
(let ((bytes (loop :for i :from 0
:for code := (cffi:mem-aref pointer :unsigned-char i)
:until (zerop code)
:collect code)))
(map 'string 'code-char bytes)))

(defun process-receive-output (process)
(let ((cffi:*default-foreign-encoding* (process-encode process)))
(%process-receive-output (process-process process))))
(pointer-to-string (%process-receive-output (process-process process)))))

(defun process-alive-p (process)
(%process-alive-p (process-process process)))

0 comments on commit 7db34da

Please sign in to comment.