Skip to content

Commit

Permalink
lsp: Add some end-to-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Jan 13, 2025
1 parent a51af8f commit eb4e816
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/esbonio/changes/941.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The language server once again offers completion suggestions for arguments to the following classes of directives `code-blocks`, `images` and `includes`
12 changes: 10 additions & 2 deletions lib/esbonio/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 42 additions & 3 deletions lib/esbonio/tests/e2e/test_e2e_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

RST_EXPECTED = EXPECTED.copy()
MYST_EXPECTED = {"eval-rst", *EXPECTED}
LEXERS = {"python", "python-console", "nix"}

UNEXPECTED = {
"macro",
Expand All @@ -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),
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand All @@ -143,14 +167,29 @@ 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),
(" ```{doctest}", None, None),
(" ```{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")
Expand Down

0 comments on commit eb4e816

Please sign in to comment.