zed-ets-language-server 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/data-parser.js +13 -14
- package/package.json +1 -1
package/lib/data-parser.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
import { logger } from './logger.js';
|
|
2
2
|
|
|
3
|
-
let stdinBuffer =
|
|
3
|
+
let stdinBuffer = '';
|
|
4
4
|
|
|
5
5
|
export function parse(data, callback) {
|
|
6
|
-
|
|
7
|
-
const dataBuffer = Buffer.isBuffer(data) ? data : Buffer.from(data, 'utf8');
|
|
8
|
-
stdinBuffer = Buffer.concat([stdinBuffer, dataBuffer]);
|
|
6
|
+
stdinBuffer += data.toString();
|
|
9
7
|
|
|
10
8
|
while (true) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const headerPart = stdinBuffer.subarray(0, headerEnd).toString('utf8');
|
|
15
|
-
const lengthMatch = headerPart.match(/Content-Length: (\d+)/);
|
|
9
|
+
// Find Content-Length header
|
|
10
|
+
const lengthMatch = stdinBuffer.match(/Content-Length: (\d+)\r\n/);
|
|
16
11
|
if (!lengthMatch) break;
|
|
17
12
|
|
|
18
13
|
const contentLength = Number.parseInt(lengthMatch[1]);
|
|
14
|
+
const headerEnd = stdinBuffer.indexOf('\r\n\r\n');
|
|
15
|
+
|
|
16
|
+
if (headerEnd === -1) break;
|
|
17
|
+
|
|
19
18
|
const messageStart = headerEnd + 4;
|
|
20
19
|
const messageEnd = messageStart + contentLength;
|
|
21
20
|
|
|
22
21
|
if (stdinBuffer.length < messageEnd) break;
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// Extract message
|
|
24
|
+
const messageJson = stdinBuffer.substring(messageStart, messageEnd);
|
|
25
|
+
stdinBuffer = stdinBuffer.substring(messageEnd);
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
28
|
const message = JSON.parse(messageJson);
|
|
29
29
|
callback(message);
|
|
30
30
|
} catch (error) {
|
|
31
|
-
logger.error(`Error parsing message: ${error.message}`);
|
|
32
|
-
stdinBuffer = Buffer.alloc(0);
|
|
31
|
+
logger.error(`Error parsing message: ${error.message} ${error.stack} ${messageJson}`);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export function clearBuffer() {
|
|
38
|
-
stdinBuffer =
|
|
37
|
+
stdinBuffer = '';
|
|
39
38
|
}
|