MCPcopy
hub / github.com/Doorman11991/smallcode / decodeMessages

Function decodeMessages

src/lsp/client.js:18–44  ·  view source on GitHub ↗
(buffer)

Source from the content-addressed store, hash-verified

16}
17
18function decodeMessages(buffer) {
19 const messages = [];
20 let remaining = buffer;
21
22 while (remaining.length > 0) {
23 const headerEnd = remaining.indexOf('\r\n\r\n');
24 if (headerEnd === -1) break;
25
26 const header = remaining.slice(0, headerEnd);
27 const lengthMatch = header.match(/Content-Length: (\d+)/);
28 if (!lengthMatch) break;
29
30 const contentLength = parseInt(lengthMatch[1]);
31 const contentStart = headerEnd + 4;
32
33 if (remaining.length < contentStart + contentLength) break;
34
35 const content = remaining.slice(contentStart, contentStart + contentLength);
36 try {
37 messages.push(JSON.parse(content));
38 } catch {}
39
40 remaining = remaining.slice(contentStart + contentLength);
41 }
42
43 return { messages, remaining };
44}
45
46// Detect which language server to use based on project files
47function detectServer(cwd) {

Callers 1

_onDataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected