{"action":"created","issue":{"url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/2580","repository_url":"https://api.github.com/repos/sphinx-doc/sphinx","labels_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/2580/labels{/name}","comments_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/2580/comments","events_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/2580/events","html_url":"https://github.com/sphinx-doc/sphinx/issues/2580","id":156821653,"number":2580,"title":"resolve_references() doesn't pass fromdocname parameter to the \"missing-reference\" event","user":{"login":"papadokolos","id":13286080,"avatar_url":"https://avatars.githubusercontent.com/u/13286080?v=3","gravatar_id":"","url":"https://api.github.com/users/papadokolos","html_url":"https://github.com/papadokolos","followers_url":"https://api.github.com/users/papadokolos/followers","following_url":"https://api.github.com/users/papadokolos/following{/other_user}","gists_url":"https://api.github.com/users/papadokolos/gists{/gist_id}","starred_url":"https://api.github.com/users/papadokolos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/papadokolos/subscriptions","organizations_url":"https://api.github.com/users/papadokolos/orgs","repos_url":"https://api.github.com/users/papadokolos/repos","events_url":"https://api.github.com/users/papadokolos/events{/privacy}","received_events_url":"https://api.github.com/users/papadokolos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-25T18:42:20Z","updated_at":"2016-05-26T01:20:27Z","closed_at":null,"body":"## Background Information: (refer here if needed)\r\nSphinx is having troubles resolving some of the references generated from my C++ code with the help of Doxygen, breathe, and .rst files.\r\n\r\nI found out that the reason for this is that sometimes `node[\"reftarget\"]`'s value is missing the namespace as a prefix. e.g. node[\"reftarget\"] == \"Foo\" instead of \"namespace::Foo\". The weird thing about it, is that it only happenes for specific parts in the document.\r\n\r\nFor example, it happenes with the `return value type` part of function's signature, but not with the same type being mentioned in the function's documentation:\r\n\r\n> ___DocumentationPageResult.html:___\r\n\r\n>ReturnType func(int a) `// Sphinx couldn't resolve ReturnType and it becomes a regular text`\r\n\r\n>    A member function.\r\n\r\n>__Parameters__\r\n    a - just a number\r\n\r\n>__Return__\r\n    ReturnType - some value to be returned `// Sphinx resolved a reference for ReturnType here!!`\r\n\r\nIn order to solve this problem i've written an extension which adds \"namespace::\" prefix the node[\"reftaget\"] and then acts exactly as `resolve_references()` (from environment.py) does for a single iteration (since resolve_references() loops over many references).\r\n\r\nThe extension significally improves the number of resolved references (there are other issues that I haven't yet figured out), and the links were created, but they linked to a wrong file path. That leads me to the problem which im here to report on:\r\n\r\n## The actual problem\r\nMy extension uses the function `resolve_xref()` to resolve missing references.\r\nThe function `resolve_xref()` returns a node with a link to the resolved reference, which considers the value of the \"fromdocname\" parameter (one of the parameters of `resolve_xref()`) - the resulted link is a relative one.\r\n\r\nUnfortunately, my extension doesn't have \"fromdocname\" value to supply, because it's not included in any of the given parameters of \"missing-reference\" event.\r\nThe function `resolve_references()` from environment.py, which calls my extension upon a \"missing-reference\" event, gets \"fromdocname\" as a parameter, but doesn't pass it through to the event. As a result, my extension can't do it's job, the links are broken...\r\n\r\nAs a temporary solution, i've edited environemt.py as follows:\r\n```c++\r\n    def resolve_references(self, doctree, fromdocname, builder):\r\n        for node in doctree.traverse(addnodes.pending_xref):\r\n            contnode = node[0].deepcopy()\r\n            newnode = None\r\n\r\n            typ = node['reftype']\r\n            target = node['reftarget']\r\n            refdoc = node.get('refdoc', fromdocname)\r\n            domain = None\r\n\r\n            try:\r\n                ...\r\n                # no new node found? try the missing-reference event\r\n                if newnode is None:\r\n                    ###################### Added this line here V (that is all)\r\n                    node['refdoc'] = refdoc\r\n                    ######################\r\n                    newnode = builder.app.emit_firstresult(\r\n                        'missing-reference', self, node, contnode)\r\n                    # still not found? warn if node wishes to be warned about or\r\n                    # we are in nit-picky mode\r\n                    if newnode is None:\r\n                        self._warn_missing_reference(refdoc, typ, target, node, domain)\r\n            except NoUri:\r\n                newnode = contnode\r\n            node.replace_self(newnode or contnode)\r\n            ...\r\n```\r\n\r\nDo you have a better solution in mind?\r\n\r\nWould love to hear your thoughts,\r\nThank you for your time."},"comment":{"url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/comments/221753411","html_url":"https://github.com/sphinx-doc/sphinx/issues/2580#issuecomment-221753411","issue_url":"https://api.github.com/repos/sphinx-doc/sphinx/issues/2580","id":221753411,"user":{"login":"jakobandersen","id":6465735,"avatar_url":"https://avatars.githubusercontent.com/u/6465735?v=3","gravatar_id":"","url":"https://api.github.com/users/jakobandersen","html_url":"https://github.com/jakobandersen","followers_url":"https://api.github.com/users/jakobandersen/followers","following_url":"https://api.github.com/users/jakobandersen/following{/other_user}","gists_url":"https://api.github.com/users/jakobandersen/gists{/gist_id}","starred_url":"https://api.github.com/users/jakobandersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakobandersen/subscriptions","organizations_url":"https://api.github.com/users/jakobandersen/orgs","repos_url":"https://api.github.com/users/jakobandersen/repos","events_url":"https://api.github.com/users/jakobandersen/events{/privacy}","received_events_url":"https://api.github.com/users/jakobandersen/received_events","type":"User","site_admin":false},"created_at":"2016-05-26T01:20:27Z","updated_at":"2016-05-26T01:20:27Z","body":"Unfortunately I don't know enough about environment.py to evaluate your suggestion. However, if there is a lookup bug in the C++ domain I would very much like to fix it. The domain should keep track of namespaces in order to resolve references. Do you have an example where the problem can be reproduced? (Or is the code you mention available somewhere?)"}}
{"actor":{"display_login":"jakobandersen"}}