예제 #1
0
def test_recv_close_pipe():
    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(None, pipein)
    pipeout.close()
    result = json_rpc_endpoint.recv_response()
    assert (result is None)
예제 #2
0
def test_send_sanity():
    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(pipeout, None)
    json_rpc_endpoint.send_request({"key_num": 1, "key_str": "some_string"})
    result = pipein.read(len(JSON_RPC_RESULT_LIST[0]))
    assert (result in JSON_RPC_RESULT_LIST)
예제 #3
0
def test_recv_wrong_header():
    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(None, pipein)
    pipeout.write(
        'Contentength: 40\r\n\r\n{"key_str": "some_string", "key_num": 1}'.
        encode("utf-8"))
    pipeout.flush()
    with pytest.raises(RuntimeError):
        result = json_rpc_endpoint.recv_response()
예제 #4
0
def test_recv_sanity():
    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(None, pipein)
    pipeout.write(
        'Content-Length: 40\r\n\r\n{"key_str": "some_string", "key_num": 1}'.
        encode("utf-8"))
    pipeout.flush()
    result = json_rpc_endpoint.recv_response()
    assert ({"key_num": 1, "key_str": "some_string"} == result)
예제 #5
0
def test_recv_missing_size():
    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(None, pipein)
    pipeout.write(
        'Content-Type: 40\r\n\r\n{"key_str": "some_string", "key_num": 1}'.
        encode("utf-8"))
    pipeout.flush()
    with pytest.raises(pylspclient.lsp_structs.ResponseError):
        result = json_rpc_endpoint.recv_response()
        print("should never get here", result)
예제 #6
0
def test_send_class():
    class RpcClass(object):
        def __init__(self, value_num, value_str):
            self.key_num = value_num
            self.key_str = value_str

    pipein, pipeout = os.pipe()
    pipein = os.fdopen(pipein, "rb")
    pipeout = os.fdopen(pipeout, "wb")
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(pipeout, None)
    json_rpc_endpoint.send_request(RpcClass(1, "some_string"))
    result = pipein.read(len(JSON_RPC_RESULT_LIST[0]))
    assert (result in JSON_RPC_RESULT_LIST)
예제 #7
0
    def run(self):
        line = self.pipe.readline().decode('utf-8')
        while line:
            print(line)
            line = self.pipe.readline().decode('utf-8')


if __name__ == "__main__":
    pyls_cmd = ["python", "-m", "pyls"]
    p = subprocess.Popen(pyls_cmd,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    read_pipe = ReadPipe(p.stderr)
    read_pipe.start()
    json_rpc_endpoint = pylspclient.JsonRpcEndpoint(p.stdin, p.stdout)
    # To work with socket: sock_fd = sock.makefile()
    lsp_endpoint = pylspclient.LspEndpoint(json_rpc_endpoint)

    lsp_client = pylspclient.LspClient(lsp_endpoint)
    capabilities = {
        'textDocument': {
            'codeAction': {
                'dynamicRegistration': True
            },
            'codeLens': {
                'dynamicRegistration': True
            },
            'colorProvider': {
                'dynamicRegistration': True
            },