Skip to content

Add TOC object entry support for C domain #13497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Features added
* #13439: linkcheck: Permit warning on every redirect with
``linkcheck_allowed_redirects = {}``.
Patch by Adam Turner.
* #13497: Support C domain objects in the table of contents.

Bugs fixed
----------
Expand Down
28 changes: 27 additions & 1 deletion sphinx/domains/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

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

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

def _object_hierarchy_parts(self, sig_node: desc_signature) -> tuple[str, ...]:
last_symbol: Symbol = self.env.current_document.c_last_symbol
return tuple(map(str, last_symbol.get_full_nested_name().names))

def _toc_entry_name(self, sig_node: desc_signature) -> str:
if not sig_node.get('_toc_parts'):
return ''

config = self.config
objtype = sig_node.parent.get('objtype')
if config.add_function_parentheses and (
objtype in {'function', 'method'}
or (objtype == 'macro' and '(' in sig_node.rawsource)
):
parens = '()'
else:
parens = ''
*parents, name = sig_node['_toc_parts']
if config.toc_object_entries_show_parents == 'domain':
return '::'.join((name + parens,))
if config.toc_object_entries_show_parents == 'hide':
return name + parens
if config.toc_object_entries_show_parents == 'all':
return '::'.join([*parents, name + parens])
return ''


class CMemberObject(CObject):
object_type = 'member'
Expand Down
Loading