swyddfa / lsp-devtools

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

pytest-lsp does not cancel pending notifications #186

Closed alcarney closed 3 weeks ago

alcarney commented 1 month ago

If I have some test code that waits for a particular notification


    # Open a text document to trigger sphinx client creation.
    lsp_client.text_document_did_open(
        types.DidOpenTextDocumentParams(
            text_document=types.TextDocumentItem(
                uri=str(test_uri),
                language_id="restructuredtext",
                version=0,
                text=pathlib.Path(test_uri).read_text(),
            )
        )
    )

    await lsp_client.wait_for_notification("sphinx/appCreated")

But the server crashes

[esbonio.SphinxManager] SphinxClient[f460d4b0-6c85-4c0d-ae00-9a7a7cb9a49b]: None -> ClientState.Starting
[esbonio.SphinxManager] Starting sphinx agent: /home/alex/.local/share/hatch/env/virtual/esbonio/3pU26gTf/hatch-test.py3.13-sphinx7/bin/python3 -S -m sphinx_agent
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/var/home/alex/Projects/swyddfa/esbonio/develop/lib/esbonio/esbonio/sphinx_agent/__main__.py", line 3, in <module>
    from .server import main
  File "/var/home/alex/Projects/swyddfa/esbonio/develop/lib/esbonio/esbonio/sphinx_agent/server.py", line 18, in <module>
    from .patches import patch_sphinx
  File "/var/home/alex/Projects/swyddfa/esbonio/develop/lib/esbonio/esbonio/sphinx_agent/patches.py", line 14, in <module>
    from .util import send_message
  File "/var/home/alex/Projects/swyddfa/esbonio/develop/lib/esbonio/esbonio/sphinx_agent/util.py", line 9, in <module>
    from sphinx.locale import _TranslationProxy
ModuleNotFoundError: No module named 'sphinx'
[esbonio.SphinxManager] SphinxClient[f460d4b0-6c85-4c0d-ae00-9a7a7cb9a49b]: ClientState.Starting -> ClientState.Errored
[esbonio.SphinxManager] sphinx-agent process exited with code: 1
[esbonio.SphinxManager] Stderr:

Then the client will hang indefinitely waiting for the notification to arrive