Skip to content

Commit e2b8fd1

Browse files
committed
Add docstring parent so that it can detect the argument types in functions.
1 parent 7870c6f commit e2b8fd1

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

mkdocstrings_handlers/vba/util.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from typing import List, Generator
33

4-
from griffe.dataclasses import Docstring
4+
from griffe.dataclasses import Docstring, Function, Parameters, Parameter
55
from griffe.docstrings import Parser
66

77
from mkdocstrings_handlers.vba.regex import re_signature, re_arg
@@ -52,19 +52,23 @@ def find_file_docstring(code: str) -> Docstring:
5252
It's the first block of comment lines before the first signature, if any.
5353
"""
5454
docstring_lines = []
55+
lineno = None
5556

56-
for line in code.splitlines():
57+
for i, line in enumerate(code.splitlines()):
5758
if is_signature(line):
5859
break
5960
if is_comment(line):
61+
if lineno is None:
62+
# This is the first docstring line
63+
lineno = i
64+
6065
docstring_lines.append(line)
6166

6267
docstring_value = "\n".join(uncomment_lines(docstring_lines))
6368

6469
return Docstring(
6570
value=docstring_value,
66-
parser=Parser.google,
67-
parser_options={},
71+
lineno=lineno,
6872
)
6973

7074

@@ -159,14 +163,31 @@ def find_procedures(code: str) -> Generator[VbaProcedureInfo, None, None]:
159163

160164
docstring_value = "\n".join(uncomment_lines(docstring_lines))
161165

166+
# See https://mkdocstrings.github.io/griffe/usage/#using-griffe-as-a-docstring-parsing-library
167+
docstring = Docstring(
168+
value=docstring_value,
169+
parser=Parser.google,
170+
parser_options={},
171+
lineno=procedure["first_line"] + 1,
172+
parent=Function(
173+
name=procedure["signature"].name,
174+
parameters=Parameters(
175+
*(
176+
Parameter(
177+
name=arg.name,
178+
annotation=arg.arg_type,
179+
default=arg.default,
180+
)
181+
for arg in procedure["signature"].args
182+
)
183+
),
184+
),
185+
)
186+
162187
# Yield it and start over.
163188
yield VbaProcedureInfo(
164189
signature=procedure["signature"],
165-
docstring=Docstring(
166-
value=docstring_value,
167-
parser=Parser.google,
168-
parser_options={},
169-
),
190+
docstring=docstring,
170191
first_line=procedure["first_line"],
171192
last_line=procedure["last_line"],
172193
source=procedure_source,

0 commit comments

Comments
 (0)