Skip to content

Commit

Permalink
lsp: Suggest eval-rst directive when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Jun 5, 2024
1 parent 7a5d688 commit 52ceaaf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/esbonio/changes/799.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The server now includes the `eval-rst` directive in its completion suggestions for MyST files
7 changes: 7 additions & 0 deletions lib/esbonio/esbonio/server/features/myst/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lsprotocol import types

from esbonio import server
from esbonio.server.features.directives import Directive
from esbonio.server.features.directives import DirectiveFeature
from esbonio.server.features.directives import completion
from esbonio.sphinx_agent.types import MYST_DIRECTIVE
Expand Down Expand Up @@ -85,6 +86,12 @@ async def complete_directives(
return None

items = []

# Include the special `eval-rst` directive
eval_rst = Directive("eval-rst", implementation=None)
if (item := render_func(context, eval_rst)) is not None:
items.append(item)

for directive in await self.directives.suggest_directives(context):
if (item := render_func(context, directive)) is not None:
items.append(item)
Expand Down
46 changes: 26 additions & 20 deletions lib/esbonio/tests/e2e/test_e2e_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,38 @@
"std:option",
}

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

UNEXPECTED = {
"macro",
"restructuredtext-test-directive",
}

RST_UNEXPECTED = {"eval-rst", *UNEXPECTED}
MYST_UNEXPECTED = UNEXPECTED.copy()


@pytest.mark.parametrize(
"text, expected, unexpected",
[
(".", None, None),
("..", EXPECTED, UNEXPECTED),
(".. ", EXPECTED, UNEXPECTED),
(".. d", EXPECTED, UNEXPECTED),
(".. code-b", EXPECTED, UNEXPECTED),
("..", RST_EXPECTED, RST_UNEXPECTED),
(".. ", RST_EXPECTED, RST_UNEXPECTED),
(".. d", RST_EXPECTED, RST_UNEXPECTED),
(".. code-b", RST_EXPECTED, RST_UNEXPECTED),
(".. codex-block:: ", None, None),
(".. c:", EXPECTED, UNEXPECTED),
(".. c:", RST_EXPECTED, RST_UNEXPECTED),
(".. _some_label:", None, None),
(" .", None, None),
(" ..", EXPECTED, UNEXPECTED),
(" .. ", EXPECTED, UNEXPECTED),
(" .. d", EXPECTED, UNEXPECTED),
(" ..", RST_EXPECTED, RST_UNEXPECTED),
(" .. ", RST_EXPECTED, RST_UNEXPECTED),
(" .. d", RST_EXPECTED, RST_UNEXPECTED),
(" .. doctest:: ", None, None),
(" .. code-b", EXPECTED, UNEXPECTED),
(" .. code-b", RST_EXPECTED, RST_UNEXPECTED),
(" .. codex-block:: ", None, None),
(" .. _some_label:", None, None),
(" .. c:", EXPECTED, UNEXPECTED),
(" .. c:", RST_EXPECTED, RST_UNEXPECTED),
],
)
@pytest.mark.asyncio(scope="session")
Expand Down Expand Up @@ -133,21 +139,21 @@ async def test_rst_directive_completions(
[
("`", None, None),
("``", None, None),
("```", EXPECTED, UNEXPECTED),
("```{", EXPECTED, UNEXPECTED),
("```{d", EXPECTED, UNEXPECTED),
("```{code-b", EXPECTED, UNEXPECTED),
("```", MYST_EXPECTED, MYST_UNEXPECTED),
("```{", MYST_EXPECTED, MYST_UNEXPECTED),
("```{d", MYST_EXPECTED, MYST_UNEXPECTED),
("```{code-b", MYST_EXPECTED, MYST_UNEXPECTED),
("```{codex-block} ", None, None),
("```{c:", EXPECTED, UNEXPECTED),
("```{c:", MYST_EXPECTED, MYST_UNEXPECTED),
(" `", None, None),
(" ``", None, None),
(" ```", EXPECTED, UNEXPECTED),
(" ```{", EXPECTED, UNEXPECTED),
(" ```{d", EXPECTED, UNEXPECTED),
(" ```", MYST_EXPECTED, MYST_UNEXPECTED),
(" ```{", MYST_EXPECTED, MYST_UNEXPECTED),
(" ```{d", MYST_EXPECTED, MYST_UNEXPECTED),
(" ```{doctest}", None, None),
(" ```{code-b", EXPECTED, UNEXPECTED),
(" ```{code-b", MYST_EXPECTED, MYST_UNEXPECTED),
(" ```{codex-block}", None, None),
(" ```{c:", EXPECTED, UNEXPECTED),
(" ```{c:", MYST_EXPECTED, MYST_UNEXPECTED),
],
)
@pytest.mark.asyncio(scope="session")
Expand Down

0 comments on commit 52ceaaf

Please sign in to comment.