def client_server():
    c2s_r, c2s_w = os.pipe()
    s2c_r, s2c_w = os.pipe()

    def start(ls: LanguageServer, fdr, fdw):
        # TODO: better patch is needed
        # disable `close()` to avoid error messages
        close = ls.loop.close
        ls.loop.close = lambda: None
        ls.start_io(os.fdopen(fdr, "rb"), os.fdopen(fdw, "wb"))
        ls.loop.close = close

    server = CMakeLanguageServer(asyncio.new_event_loop())
    server_thread = Thread(target=start, args=(server, c2s_r, s2c_w))
    server_thread.start()

    client = LanguageServer(asyncio.new_event_loop())
    client_thread = Thread(target=start, args=(client, s2c_r, c2s_w))
    client_thread.start()

    yield client, server

    client.send_notification(features.EXIT)
    server.send_notification(features.EXIT)
    server_thread.join()
    client_thread.join()
Exemplo n.º 2
0
def client_server():
    """ A fixture to setup a client/server """

    # Client to Server pipe
    csr, csw = os.pipe()
    # Server to client pipe
    scr, scw = os.pipe()

    # Run server
    server_thread = Thread(target=textx_server.start_io, args=(
        os.fdopen(csr, 'rb'), os.fdopen(scw, 'wb')
    ))
    server_thread.daemon = True
    server_thread.start()

    # Setup client
    client = LanguageServer(asyncio.new_event_loop())
    client_thread = Thread(target=client.start_io, args=(
        os.fdopen(scr, 'rb'), os.fdopen(csw, 'wb')
    ))
    client_thread.daemon = True
    client_thread.start()

    # Register client features to catch responses
    register_client_features(client)

    # Initialize server
    initialize_server(textx_server)

    yield client, textx_server

    shutdown_response = client.lsp.send_request(
        SHUTDOWN).result(timeout=CALL_TIMEOUT)

    assert shutdown_response is None
    client.send_notification(EXIT)