def send(line): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((host, port)) print(f"send: {line}") writer = JsonRpcStreamWriter(sock.makefile("wb")) writer.write(line) print(f"recv: {sock.recv(4096)}")
def send(line): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((host, port)) print(f"send: {line}") writer = JsonRpcStreamWriter(sock.makefile("wb")) writer.write(line) print(f"recv: {sock.recv(4096)}")
async def tcp_echo_client(message): reader, writer = await asyncio.open_connection("127.0.0.1", 44444) w = JsonRpcStreamWriter(WriterAdapter(writer), indent=2) w.write(message) data = await reader.read(4096) print(f"Received: {data.decode()!r}") print("Close the connection") writer.close()
def send(self, d): w = JsonRpcStreamWriter(self.p.stdin, indent=2) w.write(make_request(d))
def send(self, d): w = JsonRpcStreamWriter(self.p.stdin, indent=2) w.write(make_request(d))
JsonRpcStreamReader(sock.makefile("rb")).listen(pprint) th = threading.Thread(target=consume, daemon=True) th.start() w = JsonRpcStreamWriter(sock.makefile("wb"), indent=2) d = { "jsonrpc": "2.0", "id": str(uuid.uuid4()), "method": "initialize", "params": { "rootUri": pathlib.Path(__file__).parent.absolute().as_uri(), "initializationOptions": {}, # xxx: }, } w.write(d) d = { "jsonrpc": "2.0", "id": str(uuid.uuid4()), "method": "textDocument/completion", "params": { "textDocument": { "uri": pathlib.Path(__file__).parent.joinpath( "something.py").absolute().as_uri() }, "position": { "line": 1, "character": 7 },
# server: pyls --tcp --port 44444 -vv import pathlib import socket import uuid import threading from pprint import pprint from pyls_jsonrpc.streams import JsonRpcStreamWriter, JsonRpcStreamReader host = "localhost" port = 44444 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((host, port)) def consume(): JsonRpcStreamReader(sock.makefile("rb")).listen(pprint) th = threading.Thread(target=consume, daemon=True) th.start() w = JsonRpcStreamWriter(sock.makefile("wb"), indent=2) d = {"jsonrpc": "2.0", "id": str(uuid.uuid4()), "method": "shutdown"} w.write(d) d = {"jsonrpc": "2.0", "id": str(uuid.uuid4()), "method": "exit"} w.write(d) th.join()
import sys from pyls_jsonrpc.streams import JsonRpcStreamWriter w = JsonRpcStreamWriter(sys.stdout.buffer) w.write({"key": "value"}) w.close() # Content-Length: 16 # Content-Type: application/vscode-jsonrpc; charset=utf8 # {"key": "value"}