Skip to content

Commit

Permalink
Added TOC object entry support for the C++ domain (#11221)
Browse files Browse the repository at this point in the history
When ``toc_object_entries_show_parents = 'domain'`` in the config,
the TOC entries omit the namespaces added by the ``cpp:namespace`` and ``cpp:namespace-push`` directives.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
Rouslan and AA-Turner committed Jul 28, 2023
1 parent 97d2c5d commit d1b09b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -32,6 +32,8 @@ Features added
* #9662: Add the ``:no-typesetting:`` option to suppress textual output
and only create a linkable anchor.
Patch by Latosha Maltba.
* #11221: C++: Support domain objects in the table of contents.
Patch by Rouslan Korneychuk.

Bugs fixed
----------
Expand Down
31 changes: 31 additions & 0 deletions sphinx/domains/cpp.py
Expand Up @@ -613,6 +613,9 @@ def __init__(self, identifier: str) -> None:
assert len(identifier) != 0
self.identifier = identifier

def _stringify(self, transform: StringifyTransform) -> str:
return transform(self.identifier)

def is_anon(self) -> bool:
return self.identifier[0] == '@'

Expand Down Expand Up @@ -7432,10 +7435,38 @@ def before_content(self) -> None:
self.oldParentKey: LookupKey = self.env.ref_context['cpp:parent_key']
self.env.temp_data['cpp:parent_symbol'] = lastSymbol
self.env.ref_context['cpp:parent_key'] = lastSymbol.get_lookup_key()
self.env.temp_data['cpp:domain_name'] = (
*self.env.temp_data.get('cpp:domain_name', ()),
lastSymbol.identOrOp._stringify(str),
)

def after_content(self) -> None:
self.env.temp_data['cpp:parent_symbol'] = self.oldParentSymbol
self.env.ref_context['cpp:parent_key'] = self.oldParentKey
self.env.temp_data['cpp:domain_name'] = self.env.temp_data['cpp:domain_name'][:-1]

def _object_hierarchy_parts(self, sig_node: desc_signature) -> tuple[str, ...]:
return tuple(s.identOrOp._stringify(str) for s in
self.env.temp_data['cpp: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.env.app.config
objtype = sig_node.parent.get('objtype')
if config.add_function_parentheses and objtype in {'function', 'method'}:
parens = '()'
else:
parens = ''
*parents, name = sig_node['_toc_parts']
if config.toc_object_entries_show_parents == 'domain':
return '::'.join((*self.env.temp_data.get('cpp:domain_name', ()), 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 CPPTypeObject(CPPObject):
Expand Down

0 comments on commit d1b09b0

Please sign in to comment.