mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C, fix object types for xrefs
Add 'identifer' to all and 'type' to types. Fixes sphinx-doc/sphinx#8341
This commit is contained in:
@@ -3657,15 +3657,18 @@ class CDomain(Domain):
|
||||
name = 'c'
|
||||
label = 'C'
|
||||
object_types = {
|
||||
'function': ObjType(_('function'), 'func'),
|
||||
'member': ObjType(_('member'), 'member'),
|
||||
'macro': ObjType(_('macro'), 'macro'),
|
||||
'type': ObjType(_('type'), 'type'),
|
||||
'var': ObjType(_('variable'), 'data'),
|
||||
'enum': ObjType(_('enum'), 'enum'),
|
||||
'enumerator': ObjType(_('enumerator'), 'enumerator'),
|
||||
'struct': ObjType(_('struct'), 'struct'),
|
||||
'union': ObjType(_('union'), 'union'),
|
||||
# 'identifier' is the one used for xrefs generated in signatures, not in roles
|
||||
'member': ObjType(_('member'), 'var', 'member', 'data', 'identifier'),
|
||||
'var': ObjType(_('variable'), 'var', 'member', 'data', 'identifier'),
|
||||
'function': ObjType(_('function'), 'func', 'identifier', 'type'),
|
||||
'macro': ObjType(_('macro'), 'macro', 'identifier'),
|
||||
'struct': ObjType(_('struct'), 'struct', 'identifier', 'type'),
|
||||
'union': ObjType(_('union'), 'union', 'identifier', 'type'),
|
||||
'enum': ObjType(_('enum'), 'enum', 'identifier', 'type'),
|
||||
'enumerator': ObjType(_('enumerator'), 'enumerator', 'identifier'),
|
||||
'type': ObjType(_('type'), 'identifier', 'type'),
|
||||
# generated object types
|
||||
'functionParam': ObjType(_('function parameter'), 'identifier', 'var', 'member', 'data'), # noqa
|
||||
}
|
||||
|
||||
directives = {
|
||||
|
||||
4
tests/roots/test-domain-c-intersphinx/conf.py
Normal file
4
tests/roots/test-domain-c-intersphinx/conf.py
Normal file
@@ -0,0 +1,4 @@
|
||||
exclude_patterns = ['_build']
|
||||
extensions = [
|
||||
'sphinx.ext.intersphinx',
|
||||
]
|
||||
62
tests/roots/test-domain-c-intersphinx/index.rst
Normal file
62
tests/roots/test-domain-c-intersphinx/index.rst
Normal file
@@ -0,0 +1,62 @@
|
||||
.. c:member:: void __member = _member
|
||||
|
||||
- :any:`_member`
|
||||
- :c:member:`_member`
|
||||
- :c:var:`_member`
|
||||
- :c:data:`_member`
|
||||
|
||||
.. c:member:: void __var = _var
|
||||
|
||||
- :any:`_var`
|
||||
- :c:member:`_var`
|
||||
- :c:var:`_var`
|
||||
- :c:data:`_var`
|
||||
|
||||
.. c:member:: void __function = _function
|
||||
|
||||
- :any:`_function`
|
||||
- :c:func:`_function`
|
||||
- :c:type:`_function`
|
||||
|
||||
.. c:member:: void __macro = _macro
|
||||
|
||||
- :any:`_macro`
|
||||
- :c:macro:`_macro`
|
||||
|
||||
.. c:type:: _struct __struct
|
||||
struct _struct __structTagged
|
||||
|
||||
- :any:`_struct`
|
||||
- :c:struct:`_struct`
|
||||
- :c:type:`_struct`
|
||||
|
||||
.. c:type:: _union __union
|
||||
union _union __unionTagged
|
||||
|
||||
- :any:`_union`
|
||||
- :c:union:`_union`
|
||||
- :c:type:`_union`
|
||||
|
||||
.. c:type:: _enum __enum
|
||||
enum _enum __enumTagged
|
||||
|
||||
- :any:`_enum`
|
||||
- :c:enum:`_enum`
|
||||
- :c:type:`_enum`
|
||||
|
||||
.. c:member:: void __enumerator = _enumerator
|
||||
|
||||
- :any:`_enumerator`
|
||||
- :c:enumerator:`_enumerator`
|
||||
|
||||
.. c:type:: _type __type
|
||||
|
||||
- :any:`_type`
|
||||
- :c:type:`_type`
|
||||
|
||||
.. c:member:: void __functionParam = _functionParam.param
|
||||
|
||||
- :any:`_functionParam.param`
|
||||
- :c:member:`_functionParam.param`
|
||||
- :c:var:`_functionParam.param`
|
||||
- :c:data:`_functionParam.param`
|
||||
@@ -7,6 +7,8 @@
|
||||
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import zlib
|
||||
from xml.etree import ElementTree
|
||||
|
||||
import pytest
|
||||
@@ -14,6 +16,7 @@ import pytest
|
||||
from sphinx import addnodes
|
||||
from sphinx.addnodes import desc
|
||||
from sphinx.domains.c import DefinitionError, DefinitionParser, Symbol, _id_prefix, _max_id
|
||||
from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
|
||||
from sphinx.testing import restructuredtext
|
||||
from sphinx.testing.util import assert_node
|
||||
|
||||
@@ -642,3 +645,52 @@ def test_noindexentry(app):
|
||||
assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
|
||||
assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C function)', 'c.f', '', None)])
|
||||
assert_node(doctree[2], addnodes.index, entries=[])
|
||||
|
||||
|
||||
@pytest.mark.sphinx(testroot='domain-c-intersphinx', confoverrides={'nitpicky': True})
|
||||
def test_intersphinx(tempdir, app, status, warning):
|
||||
origSource = """\
|
||||
.. c:member:: int _member
|
||||
.. c:var:: int _var
|
||||
.. c:function:: void _function()
|
||||
.. c:macro:: _macro
|
||||
.. c:struct:: _struct
|
||||
.. c:union:: _union
|
||||
.. c:enum:: _enum
|
||||
|
||||
.. c:enumerator:: _enumerator
|
||||
|
||||
.. c:type:: _type
|
||||
.. c:function:: void _functionParam(int param)
|
||||
""" # noqa
|
||||
inv_file = tempdir / 'inventory'
|
||||
inv_file.write_bytes(b'''\
|
||||
# Sphinx inventory version 2
|
||||
# Project: C Intersphinx Test
|
||||
# Version:
|
||||
# The remainder of this file is compressed using zlib.
|
||||
''' + zlib.compress(b'''\
|
||||
_enum c:enum 1 index.html#c.$ -
|
||||
_enum._enumerator c:enumerator 1 index.html#c.$ -
|
||||
_enumerator c:enumerator 1 index.html#c._enum.$ -
|
||||
_function c:function 1 index.html#c.$ -
|
||||
_functionParam c:function 1 index.html#c.$ -
|
||||
_functionParam.param c:functionParam 1 index.html#c._functionParam -
|
||||
_macro c:macro 1 index.html#c.$ -
|
||||
_member c:member 1 index.html#c.$ -
|
||||
_struct c:struct 1 index.html#c.$ -
|
||||
_type c:type 1 index.html#c.$ -
|
||||
_union c:union 1 index.html#c.$ -
|
||||
_var c:member 1 index.html#c.$ -
|
||||
''')) # noqa
|
||||
app.config.intersphinx_mapping = {
|
||||
'https://localhost/intersphinx/c/': inv_file,
|
||||
}
|
||||
app.config.intersphinx_cache_limit = 0
|
||||
# load the inventory and check if it's done correctly
|
||||
normalize_intersphinx_mapping(app, app.config)
|
||||
load_mappings(app)
|
||||
|
||||
app.builder.build_all()
|
||||
ws = filter_warnings(warning, "index")
|
||||
assert len(ws) == 0
|
||||
|
||||
Reference in New Issue
Block a user