zed-ets-language-server 2.3.2 → 2.3.4

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/index.js CHANGED
@@ -48,12 +48,7 @@ async function main() {
48
48
  });
49
49
 
50
50
  // Set up forwarding of process.stdin to serverProcess IPC
51
- // Note: We intentionally do NOT call setEncoding('utf8') here because:
52
- // 1. LSP Content-Length is measured in bytes, not characters
53
- // 2. TCP data can be split at arbitrary byte boundaries, including mid-multibyte UTF-8
54
- // 3. If setEncoding('utf8') is used and data splits mid-character, the decoder may
55
- // produce replacement characters or corrupt the byte boundary tracking
56
- // By keeping stdin as raw Buffer, data-parser.js can correctly track byte positions
51
+ process.stdin.setEncoding('utf8');
57
52
  process.stdin.on('data', (data) => parse(data, async (message) => {
58
53
  // This special ets request is required in document: https://github.com/ohosvscode/arkTS/tree/next/packages/language-server
59
54
  // When this goes wrong, ETS UI decorators and functions will be type of any
@@ -62,6 +57,8 @@ async function main() {
62
57
 
63
58
  const ohos = await listHelperPaths(initializationOptions.tsdk, initializationOptions.ohosSdkPath);
64
59
 
60
+ // Send both `ohos` and `ets` keys to stay compatible with
61
+ // @arkts/language-server v1.2.x (uses `ohos`) and v1.3.x+ (uses `ets`).
65
62
  const etsSpecialRequest = {
66
63
  jsonrpc: '2.0',
67
64
  id: Date.now(),
@@ -71,6 +68,7 @@ async function main() {
71
68
  tsdk: initializationOptions.tsdk,
72
69
  },
73
70
  ohos: ohos,
71
+ ets: ohos,
74
72
  },
75
73
  };
76
74
 
@@ -79,6 +77,7 @@ async function main() {
79
77
  tsdk: initializationOptions.tsdk,
80
78
  };
81
79
  generalInitRequest.params.initializationOptions.ohos = ohos;
80
+ generalInitRequest.params.initializationOptions.ets = ohos;
82
81
 
83
82
  logger.info(JSON.stringify(generalInitRequest));
84
83
  logger.info(JSON.stringify(etsSpecialRequest));
@@ -1,39 +1,38 @@
1
1
  import { logger } from './logger.js';
2
2
 
3
- let stdinBuffer = Buffer.alloc(0);
3
+ let stdinBuffer = '';
4
4
 
5
5
  export function parse(data, callback) {
6
- // Convert string to Buffer if necessary (happens when stdin.setEncoding('utf8') is used)
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
- const headerEnd = stdinBuffer.indexOf('\r\n\r\n');
12
- if (headerEnd === -1) break;
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
- const messageJson = stdinBuffer.subarray(messageStart, messageEnd).toString('utf8');
25
- stdinBuffer = stdinBuffer.subarray(messageEnd);
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 = Buffer.alloc(0);
37
+ stdinBuffer = '';
39
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zed-ets-language-server",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "ETS language server wrapper for Zed ArkTS extension.",
5
5
  "type": "module",
6
6
  "main": "index.js",