swyddfa / lsp-devtools

Tooling for working with language servers and clients.
https://lsp-devtools.readthedocs.io/en/latest/
47 stars 8 forks source link

Missing test coverage #172

Open OhioDschungel6 opened 1 month ago

OhioDschungel6 commented 1 month ago

The test coverage of the language server is not working with the current setup if the language server is also implemented in python. The problem seems to be, that client.shutdown_session() is not waiting for the async subprocess to finish gracefully.

The following workaround seems to work.

@pytest_lsp.fixture(  # type: ignore[misc]
    config=ClientServerConfig(
        server_command=[sys.executable, "..."],
    )
)
async def client(lsp_client: LanguageClient):  # type: ignore[no-untyped-def]
    # Setup
    await lsp_client.initialize_session(
        InitializeParams(
            capabilities=client_capabilities("visual-studio-code"),
        )
    )

    yield lsp_client

    # Teardown
    await lsp_client.shutdown_session()
    # Needed, otherwise the coverage of the server process is not collected.
    server_process = lsp_client._server
    if server_process:
        await server_process.wait()