Describe the bug
When using the CSS Modules Kit extension in Zed, the language server crashes with a SyntaxError: Unexpected non-whitespace character after JSON error.
Cause
This happens because the internal Node.js LSP proxy wrapper script generated for the extension uses string concatenation and .length on strings to determine the message slicing point. However, the LSP protocol defines Content-Length in bytes, not characters. When the stream contains multi-byte characters (such as emojis or special symbols), .length returns a lower number than the actual byte count, cutting off the JSON payload prematurely and causing JSON.parse to fail.
Error Logs
Error processing message: SyntaxError: Unexpected non-whitespace character after JSON at position 4397 (line 1 column 4398)
at JSON.parse (<anonymous>)
at Socket.<anonymous> (data:text/javascript;base64,Y29uc3QgeyBzdGRpbiwgc3Rkb3V0IH0gPSBwcm9jZXNzOwoKc3RkaW4uc2V0RW5jb2RpbmcoInV0ZjgiKTsKCmZ1bmN0aW9uIHNlbmQobXNnKSB7CiAgY29uc3QganNvbiA9IEpTT04uc3RyaW5naWZ5KG1zZyk7CiAgY29uc3QgbGVuID0gQnVmZmVyLmJ5dGVMZW5ndGgoanNvbiwgInV0ZjgiKTsKICBzdGRvdXQud3JpdGUoYENvbnRlbnQtTGVuZ3RoOiAke2xlbn1cclxuXHJcbmApOwogIHN0ZG91dC53cml0ZShqc29uKTsKfQoKbGV0IGJ1ZmZlciA9ICIiOwpsZXQgY29udGVudExlbmd0aCA9IDA7CgpzdGRpbi5vbigiZGF0YSIsIChjaHVuaykgPT4gewogIGJ1ZmZlciArPSBjaHVuazsKCiAgd2hpbGUgKHRydWUpIHsKICAgIGlmIChjb250ZW50TGVuZ3RoID09PSAwKSB7CiAgICAgIGNvbnN0IGhlYWRlckVuZCA9IGJ1ZmZlci5pbmRleE9mKCJcclxuXHJcbiIpOwogICAgICBpZiAoaGVhZGVyRW5kID09PSAtMSkgcmV0dXJuOwoKICAgICAgY29uc3QgaGVhZGVyID0gYnVmZmVyLnNsaWNlKDAsIGhlYWRlckVuZCk7CiAgICAgIGNvbnN0IG1hdGNoID0gaGVhZGVyLm1hdGNoKC9Db250ZW50LUxlbmd0aDogKFxkKykvaSk7CiAgICAgIGlmICghbWF0Y2gpIHRldHVybjsgLy8gSWdub3JlIG1hbGZvcm1lZCBoZWFkZXJzCgogICAgICBjb250ZW50TGVuZ3RoID0gcGFyc2VJbnQobWF0Y2hbMV0sIDEwKTsKICAgICAgYnVmZmVyID0gYnVmZmVyLnNsaWNlKGhlYWRlckVuZCArIDQpOwogICAgfQoKICAgIC8vIFdhaXQgZm9yIHRoZSBmdWxsIG1lc3NhZ2UgYm9keQogICAgaWYgKGJ1ZmZlci5sZW5ndGggPCBjb250ZW50TGVuZ3RoKSByZXR1cm47CgogICAgY29uc3QgbWVzc2FnZUpzb24gPSBidWZmZXIuc2xpY2UoMCwgY29udGVudExlbmd0aCk7CiAgICBidWZmZXIgPSBidWZmZXIuc2xpY2UoY29udGVudExlbmd0aCk7CiAgICBjb250ZW50TGVuZ3RoID0gMDsgLy8gUmVzZXQgZm9yIHRoZSBuZXh0IG1lc3NhZ2UKCiAgICB0cnkgewogICAgICBjb25zdCByZXEgPSBKU09OLnBhcnNlKG1lc3NhZ2VKc29uKTsKCiAgICAgIGlmIChyZXEubWV0aG9kID09PSAiaW5pdGlhbGl6ZSIpIHsKICAgICAgICBzZW5kKHsKICAgICAgICAgIGpzb25ycGM6ICIyLjAiLAogICAgICAgICAgaWQ6IHJlcS5pZCwKICAgICAgICAgIHJlc3VsdDogewogICAgICAgICAgICBjYXBhYmlsaXRpZXM6IHt9LCAvLyBNaW5pbWFsIGNhcGFiaWxpdGllcwogICAgICAgICAgfSwKICAgICAgICB9KTsKICAgICAgfSBlbHNlIGlmIChyZXEubWV0aG9kID09PSAic2h1dGRvd24iKSB7CiAgICAgICAgLy8gUmVzcG9uZCB0byBzaHV0ZG93biBiZWZvcmUgZXhpdGluZwogICAgICAgIHNlbmQoewogICAgICAgICAganNvbnJwYzogIjIuMCIsCiAgICAgICAgICBpZDogcmVxLmlkLAogICAgICAgICAgcmVzdWx0OiBudWxsLAogICAgICAgIH0pOwogICAgICAgIC8vIFRoZSBjbGllb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9zc2libGUKICAgIH0KICB9Cn0pOw==:39:24)
Suggested Fix
The script needs to process the stream as a raw binary Buffer instead of calling stdin.setEncoding("utf8").
Using Buffer.concat(), buffer.indexOf("\r\n\r\n"), and slicing with buffer.subarray() based on exact byte counts (comparing buffer.length against contentLength only when it is a raw buffer) will prevent multi-byte string fragmentation and fix the JSON parsing crash.
Zed: v1.3.7
Extension: v0.1.1
OS: Ubuntu 24.04.4 LTS
Describe the bug
When using the CSS Modules Kit extension in Zed, the language server crashes with a
SyntaxError: Unexpected non-whitespace character after JSONerror.Cause
This happens because the internal Node.js LSP proxy wrapper script generated for the extension uses string concatenation and
.lengthon strings to determine the message slicing point. However, the LSP protocol definesContent-Lengthin bytes, not characters. When the stream contains multi-byte characters (such as emojis or special symbols),.lengthreturns a lower number than the actual byte count, cutting off the JSON payload prematurely and causingJSON.parseto fail.Error Logs
Suggested Fix
The script needs to process the stream as a raw binary
Bufferinstead of callingstdin.setEncoding("utf8").Using
Buffer.concat(),buffer.indexOf("\r\n\r\n"), and slicing withbuffer.subarray()based on exact byte counts (comparingbuffer.lengthagainstcontentLengthonly when it is a raw buffer) will prevent multi-byte string fragmentation and fix the JSON parsing crash.Zed: v1.3.7
Extension: v0.1.1
OS: Ubuntu 24.04.4 LTS