Implement get_full_qualified_name() to CPPDomain (refs: #3630)

This commit is contained in:
Takeshi KOMIYA
2017-04-23 11:33:49 +09:00
parent 96fa6d2972
commit 44b6044d4b
6 changed files with 48 additions and 0 deletions

View File

@@ -5032,6 +5032,20 @@ class CPPDomain(Domain):
newestId = symbol.declaration.get_newest_id()
yield (name, name, objectType, docname, newestId, 1)
def get_full_qualified_name(self, node):
# type: (nodes.Node) -> unicode
target = node.get('reftarget', None)
if target is None:
return None
parentKey = node.get("cpp:parent_key", None)
if parentKey is None:
return None
rootSymbol = self.data['root_symbol']
parentSymbol = rootSymbol.direct_lookup(parentKey)
parentName = parentSymbol.get_full_nested_name()
return '::'.join([text_type(parentName), target])
def setup(app):
# type: (Sphinx) -> Dict[unicode, Any]

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
extensions = ['sphinx.ext.intersphinx']
master_doc = 'index'

View File

@@ -0,0 +1,6 @@
test-ext-intersphinx-cppdomain
==============================
.. cpp:namespace:: foo
:cpp:class:`Bar`

View File

@@ -13,6 +13,8 @@ import re
from six import text_type
import pytest
from mock import Mock
from docutils import nodes
from sphinx import addnodes
from sphinx.domains.cpp import DefinitionParser, DefinitionError, NoOldIdError

View File

@@ -212,6 +212,26 @@ def test_missing_reference_stddomain(tempdir, app, status, warning):
assert rn.astext() == 'ls -l'
@pytest.mark.sphinx('html', testroot='ext-intersphinx-cppdomain')
def test_missing_reference_cppdomain(tempdir, app, status, warning):
inv_file = tempdir / 'inventory'
inv_file.write_bytes(inventory_v2)
app.config.intersphinx_mapping = {
'https://docs.python.org/': inv_file,
}
app.config.intersphinx_cache_limit = 0
# load the inventory and check if it's done correctly
load_mappings(app)
app.build()
html = (app.outdir / 'index.html').text()
assert ('<a class="reference external"'
' href="https://docs.python.org/index.html#cpp_foo_bar"'
' title="(in foo v2.0)"><code class="xref cpp cpp-class docutils literal">'
'<span class="pre">Bar</span></code></a>' in html)
def test_missing_reference_jsdomain(tempdir, app, status, warning):
inv_file = tempdir / 'inventory'
inv_file.write_bytes(inventory_v2)

View File

@@ -34,6 +34,8 @@ module1 py:module 0 foo.html#module-module1 Long Module desc
module2 py:module 0 foo.html#module-$ -
module1.func py:function 1 sub/foo.html#$ -
CFunc c:function 2 cfunc.html#CFunc -
foo::Bar cpp:class 1 index.html#cpp_foo_bar -
foo::Bar::baz cpp:function 1 index.html#cpp_foo_bar_baz -
a term std:term -1 glossary.html#term-a-term -
ls.-l std:cmdoption 1 index.html#cmdoption-ls-l -
docname std:doc -1 docname.html -