Skip to content

Commit fdc0e14

Browse files
committed
Add TOC object entry support for C domain
This is based on the C++ implementation. Implements #11424
1 parent 5e07baf commit fdc0e14

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sphinx/domains/c/__init__.py

+27-1
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)