mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added TOC object entry support for the C++ domain (#11221)
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>
This commit is contained in:
parent
97d2c5da2f
commit
d1b09b04c2
2
CHANGES
2
CHANGES
@ -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
|
||||
----------
|
||||
|
@ -613,6 +613,9 @@ class ASTIdentifier(ASTBase):
|
||||
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] == '@'
|
||||
|
||||
@ -7432,10 +7435,38 @@ class CPPObject(ObjectDescription[ASTDeclaration]):
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user