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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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