-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlsp_debug.py
More file actions
65 lines (54 loc) · 1.56 KB
/
lsp_debug.py
File metadata and controls
65 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# lsp_debug_fixed.py
import subprocess
import json
import sys
import os
def send_request(proc, request):
"""Send LSP request and read response"""
content = json.dumps(request)
header = f"Content-Length: {len(content)}\r\n\r\n"
message = header + content
proc.stdin.write(message.encode())
proc.stdin.flush()
# Read header
headers = {}
while True:
line = proc.stdout.readline().decode().strip()
if not line:
break
key, value = line.split(": ", 1)
headers[key] = value
# Read content
if "Content-Length" in headers:
content_length = int(headers["Content-Length"])
content = proc.stdout.read(content_length).decode()
return json.loads(content)
return None
# Start LSP server
proc = subprocess.Popen(
["./target/release/t-linter", "lsp", "--stdio"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={**dict(os.environ), "RUST_LOG": "trace"}
)
# Minimal initialize request
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"processId": None,
"capabilities": {}
}
}
print("Sending initialize request...")
print(f"Request: {json.dumps(init_request, indent=2)}")
response = send_request(proc, init_request)
print(f"Initialize response: {json.dumps(response, indent=2)}")
# Check stderr for errors
stderr_output = proc.stderr.read(1024).decode() if proc.stderr else ""
if stderr_output:
print(f"Stderr: {stderr_output}")
proc.terminate()