Skip to content

Commit c4d3705

Browse files
CynerdAA-Turner
andauthored
Support C domain objects in the table of contents (#13497)
Co-authored-by: Adam Turner <[email protected]>
1 parent 3b46823 commit c4d3705

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Features added
1919
* #13439: linkcheck: Permit warning on every redirect with
2020
``linkcheck_allowed_redirects = {}``.
2121
Patch by Adam Turner.
22+
* #13497: Support C domain objects in the table of contents.
2223

2324
Bugs fixed
2425
----------

sphinx/domains/c/__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
from docutils.nodes import Element, Node, TextElement, system_message
4141

42-
from sphinx.addnodes import pending_xref
42+
from sphinx.addnodes import desc_signature, pending_xref
4343
from sphinx.application import Sphinx
4444
from sphinx.builders import Builder
4545
from sphinx.domains.c._symbol import LookupKey
@@ -309,6 +309,32 @@ def after_content(self) -> None:
309309
self.env.current_document.c_parent_symbol = self.oldParentSymbol
310310
self.env.ref_context['c:parent_key'] = self.oldParentKey
311311

312+
def _object_hierarchy_parts(self, sig_node: desc_signature) -> tuple[str, ...]:
313+
last_symbol: Symbol = self.env.current_document.c_last_symbol
314+
return tuple(map(str, last_symbol.get_full_nested_name().names))
315+
316+
def _toc_entry_name(self, sig_node: desc_signature) -> str:
317+
if not sig_node.get('_toc_parts'):
318+
return ''
319+
320+
config = self.config
321+
objtype = sig_node.parent.get('objtype')
322+
if config.add_function_parentheses and (
323+
objtype in {'function', 'method'}
324+
or (objtype == 'macro' and '(' in sig_node.rawsource)
325+
):
326+
parens = '()'
327+
else:
328+
parens = ''
329+
*parents, name = sig_node['_toc_parts']
330+
if config.toc_object_entries_show_parents == 'domain':
331+
return '::'.join((name + parens,))
332+
if config.toc_object_entries_show_parents == 'hide':
333+
return name + parens
334+
if config.toc_object_entries_show_parents == 'all':
335+
return '::'.join([*parents, name + parens])
336+
return ''
337+
312338

313339
class CMemberObject(CObject):
314340
object_type = 'member'

0 commit comments

Comments
 (0)