swyddfa / lsp-devtools

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

Missing test coverage #172

Closed OhioDschungel6 closed 2 months ago

OhioDschungel6 commented 5 months 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()
alcarney commented 2 months ago

Fixed by #173, #181