Skip to content

Commit 4f6aa20

Browse files
authored
Fix missing signatures for docstrings in Markdown (#457)
1 parent d339272 commit 4f6aa20

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

pylsp/_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ def format_docstring(
209209
if markup_kind == "markdown":
210210
try:
211211
value = docstring_to_markdown.convert(contents)
212-
return {"kind": "markdown", "value": value}
213212
except docstring_to_markdown.UnknownFormatError:
214213
# try to escape the Markdown syntax instead:
215214
value = escape_markdown(contents)

test/test_utils.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from unittest import mock
1010

1111
from flaky import flaky
12+
from docstring_to_markdown import UnknownFormatError
1213

1314
from pylsp import _utils
1415
from pylsp.python_lsp import PythonLSPServer, start_io_lang_server
@@ -154,3 +155,53 @@ def test_clip_column():
154155
assert _utils.clip_column(2, ["123\n", "123"], 0) == 2
155156
assert _utils.clip_column(3, ["123\n", "123"], 0) == 3
156157
assert _utils.clip_column(4, ["123\n", "123"], 1) == 3
158+
159+
160+
@mock.patch("docstring_to_markdown.convert")
161+
def test_format_docstring_valid_rst_signature(mock_convert):
162+
"""Test that a valid RST docstring includes the function signature."""
163+
docstring = """A function docstring.
164+
165+
Parameters
166+
----------
167+
a : str, something
168+
"""
169+
170+
# Mock the return value to avoid depedency on the real thing
171+
mock_convert.return_value = """A function docstring.
172+
173+
#### Parameters
174+
175+
- `a`: str, something
176+
"""
177+
178+
markdown = _utils.format_docstring(
179+
docstring,
180+
"markdown",
181+
["something(a: str) -> str"],
182+
)["value"]
183+
184+
assert markdown.startswith(
185+
_utils.wrap_signature("something(a: str) -> str"),
186+
)
187+
188+
189+
@mock.patch("docstring_to_markdown.convert", side_effect=UnknownFormatError)
190+
def test_format_docstring_invalid_rst_signature(_):
191+
"""Test that an invalid RST docstring includes the function signature."""
192+
docstring = """A function docstring.
193+
194+
Parameters
195+
----------
196+
a : str, something
197+
"""
198+
199+
markdown = _utils.format_docstring(
200+
docstring,
201+
"markdown",
202+
["something(a: str) -> str"],
203+
)["value"]
204+
205+
assert markdown.startswith(
206+
_utils.wrap_signature("something(a: str) -> str"),
207+
)

0 commit comments

Comments
 (0)