Skip to content

Commit fcc5f76

Browse files
authored
Fix C++ apigen support for macros with Sphinx >= 7.4 (#395)
1 parent 69e685a commit fcc5f76

2 files changed

Lines changed: 52 additions & 9 deletions

File tree

sphinx_immaterial/apidoc/cpp/symbol_ids.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,23 @@ def add_declaration(declaration, docname: str, line: int):
129129
symbol.siblingBelow.siblingAbove = siblingAbove
130130
symbol.siblingBelow = None
131131

132-
# Remove duplicate symbol that was just created
133-
for other_symbol in symbol.parent._children:
134-
if other_symbol.declaration is declaration:
135-
assert other_symbol.isRedeclaration
136-
other_symbol.remove()
137-
break
132+
parent_children = symbol.parent._children
133+
if isinstance(parent_children, list):
134+
# Remove duplicate symbol that was just created
135+
for other_symbol in symbol.parent._children:
136+
if other_symbol.declaration is declaration:
137+
assert other_symbol.isRedeclaration
138+
other_symbol.remove()
139+
break
140+
else:
141+
raise AssertionError(
142+
"Duplicate symbol not found: %r" % (symbol.dump(2),)
143+
)
138144
else:
139-
raise AssertionError(
140-
"Duplicate symbol not found: %r" % (symbol.dump(2),)
141-
)
145+
# Updated C domain that stores children as a dict and does
146+
# not create duplicates
147+
# (https://github.com/sphinx-doc/sphinx/pull/12162).
148+
pass
142149
return symbol
143150

144151
parentSymbol.add_declaration = add_declaration

tests/cpp_apigen_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,39 @@ def test_unnamed_template_parameter(immaterial_make_app):
3636
app.build()
3737

3838
assert not app._warning.getvalue()
39+
40+
41+
def test_macro(immaterial_make_app):
42+
app = immaterial_make_app(
43+
extra_conf="""
44+
extensions.append("sphinx_immaterial.apidoc.cpp.apigen")
45+
""",
46+
confoverrides=dict(
47+
nitpicky=True,
48+
cpp_apigen_configs=[
49+
dict(
50+
document_prefix="cpp_apigen_generated/",
51+
api_parser_config=dict(
52+
input_content=r"""
53+
/// Tests something.
54+
///
55+
/// \ingroup Array
56+
#define IS_ARRAY(x) x + 1
57+
""",
58+
compiler_flags=["-std=c++17", "-x", "c++"],
59+
verbose=True,
60+
),
61+
),
62+
],
63+
),
64+
files={
65+
"index.rst": """
66+
.. cpp-apigen-group:: Array
67+
68+
"""
69+
},
70+
)
71+
72+
app.build()
73+
74+
assert not app._warning.getvalue()

0 commit comments

Comments
 (0)