From eb4e816b957f8ad643b9396d57855530273df2a9 Mon Sep 17 00:00:00 2001 From: Alex Carney Date: Mon, 13 Jan 2025 23:22:42 +0000 Subject: [PATCH] lsp: Add some end-to-end tests --- lib/esbonio/changes/941.feature.md | 1 + lib/esbonio/tests/e2e/conftest.py | 12 +++++- lib/esbonio/tests/e2e/test_e2e_directives.py | 45 ++++++++++++++++++-- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 lib/esbonio/changes/941.feature.md diff --git a/lib/esbonio/changes/941.feature.md b/lib/esbonio/changes/941.feature.md new file mode 100644 index 00000000..08d84e68 --- /dev/null +++ b/lib/esbonio/changes/941.feature.md @@ -0,0 +1 @@ +The language server once again offers completion suggestions for arguments to the following classes of directives `code-blocks`, `images` and `includes` diff --git a/lib/esbonio/tests/e2e/conftest.py b/lib/esbonio/tests/e2e/conftest.py index dfb347dc..ea66c23d 100644 --- a/lib/esbonio/tests/e2e/conftest.py +++ b/lib/esbonio/tests/e2e/conftest.py @@ -26,11 +26,19 @@ async def client(lsp_client: LanguageClient, uri_for, tmp_path_factory): await lsp_client.initialize_session( types.InitializeParams( capabilities=types.ClientCapabilities( - # Signal pull diagnostic support text_document=types.TextDocumentClientCapabilities( + completion=types.CompletionClientCapabilities( + completion_item=types.ClientCompletionItemOptions( + documentation_format=[ + types.MarkupKind.Markdown, + types.MarkupKind.PlainText, + ] + ), + ), + # Signal pull diagnostic support diagnostic=types.DiagnosticClientCapabilities( dynamic_registration=False - ) + ), ), # Signal workDoneProgress/create support. window=types.WindowClientCapabilities( diff --git a/lib/esbonio/tests/e2e/test_e2e_directives.py b/lib/esbonio/tests/e2e/test_e2e_directives.py index d9ff1aee..8611b881 100644 --- a/lib/esbonio/tests/e2e/test_e2e_directives.py +++ b/lib/esbonio/tests/e2e/test_e2e_directives.py @@ -23,7 +23,6 @@ RST_EXPECTED = EXPECTED.copy() MYST_EXPECTED = {"eval-rst", *EXPECTED} -LEXERS = {"python", "python-console", "nix"} UNEXPECTED = { "macro", @@ -33,10 +32,19 @@ RST_UNEXPECTED = {"eval-rst", *UNEXPECTED} MYST_UNEXPECTED = UNEXPECTED.copy() +# Code blocks +LEXERS = {"python", "python-console", "nix"} + +# Filepaths +ROOT_FILES = {"conf.py", "index.rst", "myst", "rst"} +RST_FILES = {"directives.rst", "roles.rst", "domains"} +MYST_FILES = {"directives.md", "roles.md"} + @pytest.mark.parametrize( "text, expected, unexpected", [ + # Test cases covering directive name completion (".", None, None), ("..", RST_EXPECTED, RST_UNEXPECTED), (".. ", RST_EXPECTED, RST_UNEXPECTED), @@ -54,6 +62,21 @@ (" .. codex-block:: ", None, None), (" .. _some_label:", None, None), (" .. c:", RST_EXPECTED, RST_UNEXPECTED), + # Test cases covering directive argument completion for... + # + # -- pygments lexers + (".. code-block:: ", LEXERS, None), + (".. highlight:: ", LEXERS, None), + (".. sourcecode:: ", LEXERS, None), + # -- filepaths + (".. image:: /", ROOT_FILES, None), + (".. image:: ../", ROOT_FILES, None), + (".. image:: ", RST_FILES, None), + (".. image:: .", RST_FILES, None), + (".. image:: ./", RST_FILES, None), + (".. figure:: ./", RST_FILES, None), + (".. include:: ./", RST_FILES, None), + (".. literalinclude:: ./", RST_FILES, None), ], ) @pytest.mark.asyncio(loop_scope="session") @@ -132,9 +155,10 @@ async def test_rst_directive_completions( @pytest.mark.parametrize( "text, expected, unexpected", [ + # Test cases covering directive name completions ("`", None, None), ("``", None, None), - # Unless the user types a '{', we should suggest languauge names + # -- Unless the user types a '{', we should suggest languauge names ("```", LEXERS, MYST_EXPECTED | MYST_UNEXPECTED), ("```{", MYST_EXPECTED, MYST_UNEXPECTED), ("```{d", MYST_EXPECTED, MYST_UNEXPECTED), @@ -143,7 +167,7 @@ async def test_rst_directive_completions( ("```{c:", MYST_EXPECTED, MYST_UNEXPECTED), (" `", None, None), (" ``", None, None), - # Unless the user types a '{', we should suggest languauge names + # -- Unless the user types a '{', we should suggest languauge names (" ```", LEXERS, MYST_EXPECTED | MYST_UNEXPECTED), (" ```{", MYST_EXPECTED, MYST_UNEXPECTED), (" ```{d", MYST_EXPECTED, MYST_UNEXPECTED), @@ -151,6 +175,21 @@ async def test_rst_directive_completions( (" ```{code-b", MYST_EXPECTED, MYST_UNEXPECTED), (" ```{codex-block}", None, None), (" ```{c:", MYST_EXPECTED, MYST_UNEXPECTED), + # Test cases covering directive argument completions for... + # + # -- pygments lexers + ("```{code-block} ", LEXERS, None), + ("```{highlight} ", LEXERS, None), + ("```{sourcecode} ", LEXERS, None), + # -- filepaths + ("```{image} /", ROOT_FILES, None), + ("```{image} ../", ROOT_FILES, None), + ("```{image} ", MYST_FILES, None), + ("```{image} .", MYST_FILES, None), + ("```{image} ./", MYST_FILES, None), + ("```{figure} ./", MYST_FILES, None), + ("```{include} ./", MYST_FILES, None), + ("```{literalinclude} ./", MYST_FILES, None), ], ) @pytest.mark.asyncio(loop_scope="session")