-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsolve_part1.py
93 lines (83 loc) · 1.74 KB
/
solve_part1.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from pwn import *
from pprint import pp
import json
import sys
# context.log_level = 'debug'
# io = process(
# ["./lemminx-linux"],
# env={"LEMMINX_DEBUG": "true"},
# )
host = sys.argv[1]
port = int(sys.argv[2])
io = remote(host, port)
def rpc(io, obj):
s = json.dumps(obj)
io.send(f"Content-Length: {len(s)}\r\n\r\n{s}".encode())
def recv(io):
io.recvuntil(b"Content-Length: ")
n = int(io.recvlineS().strip())
io.recvn(2) # \r\n\r\n
r = io.recvn(n).decode()
return json.loads(r)
rpc(
io,
{
"jsonrpc": "2.0",
"method": "initialize",
"params": json.loads(open("init.json").read()),
"id": 1,
},
)
print("init")
pp(recv(io)) # initialize response
rpc(
io,
{
"jsonrpc": "2.0",
"method": "initialized",
"params": {},
"id": 1,
},
)
rpc(
io,
{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "file:///home/maple3142/tmp/hello.xml",
"languageId": "xml",
"version": 1,
"text": open("hello.xml").read(),
}
},
},
)
print("didOpen hello.xml")
pp(resp := recv(io)) # client/registerCapability
rpc(
io,
{
"jsonrpc": "2.0",
"id": resp["id"],
"result": None,
},
)
pp(recv(io)) # textDocument/publishDiagnostics
rpc(
io,
{
"jsonrpc": "2.0",
"method": "textDocument/hover",
"params": {
"textDocument": {"uri": "file:///home/maple3142/tmp/hello.xml"},
"position": {"line": 4, "character": 6}
},
'id': 487
},
)
print('hovered')
pp(recv(io))
print("interactive")
io.interactive()