Skip to content

Commit

Permalink
deprecate "ns" ref in favor of "namespace"
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 3, 2023
1 parent 64cb300 commit 4718cb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ Cross Referencing
The following roles refer to php objects and are links are generated if a
matching directive is found:

.. rst:role:: php:ns
.. rst:role:: php:namespace
Reference a namespace. Nested namespaces need to be separated by two \\ due
to the syntax of ReST::
.. php:ns:`LibraryName\\SubPackage` will work correctly.
.. php:namespace:`LibraryName\\SubPackage` will work correctly.

.. rst:role:: php:func
Expand Down
12 changes: 9 additions & 3 deletions sphinxcontrib/phpdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class PhpDomain(Domain):
"class": ObjType(_("class"), "class", "obj"),
"attr": ObjType(_("attribute"), "attr", "obj"),
"exception": ObjType(_("exception"), "exc", "obj"),
"namespace": ObjType(_("namespace"), "ns", "obj"),
"namespace": ObjType(_("namespace"), "namespace", "obj"),
"interface": ObjType(_("interface"), "interface", "obj"),
"trait": ObjType(_("trait"), "trait", "obj"),
"enum": ObjType(_("enum"), "enum", "obj"),
Expand Down Expand Up @@ -784,7 +784,8 @@ class PhpDomain(Domain):
"meth": PhpXRefRole(fix_parens=False),
"attr": PhpXRefRole(),
"const": PhpXRefRole(),
"ns": PhpXRefRole(),
"namespace": PhpXRefRole(),
"ns": PhpXRefRole(), # deprecated, use "namespace"
"obj": PhpXRefRole(),
"interface": PhpXRefRole(),
"trait": PhpXRefRole(),
Expand Down Expand Up @@ -826,7 +827,12 @@ def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode):
return []

def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
if typ == "ns" or typ == "obj" and target in self.data["namespaces"]:
if (
typ == "namespace"
or typ == "ns"
or typ == "obj"
and target in self.data["namespaces"]
):
docname, synopsis, deprecated = self.data["namespaces"].get(
target, ("", "", "")
)
Expand Down
4 changes: 2 additions & 2 deletions test/rst_doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ <h3>Test Case - not including namespace<a class="headerlink" href="#test-case-no
<p>Within a namespace context you don&#x2019;t need to include the namespace in links.</p>
<p>
<a class="reference internal" href="#namespace-LibraryName">
<code class="xref php php-ns docutils literal notranslate">
<code class="xref php php-namespace docutils literal notranslate">
<span class="pre">LibraryName</span>
</code>
</a>
Expand Down Expand Up @@ -1249,7 +1249,7 @@ <h2>Nested namespaces<a class="headerlink" href="#namespace-LibraryName\SubPacka
<h3>Test Case - Test subpackage links<a class="headerlink" href="#test-case-test-subpackage-links" title="Permalink to this heading">&#xB6;</a></h3>
<p>
<a class="reference internal" href="#namespace-LibraryName\SubPackage">
<code class="xref php php-ns docutils literal notranslate">
<code class="xref php php-namespace docutils literal notranslate">
<span class="pre">LibraryName\SubPackage</span>
</code>
</a>
Expand Down
4 changes: 2 additions & 2 deletions test/rst_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Test Case - not including namespace
Within a namespace context you don't need to include the namespace in links.
:php:ns:`LibraryName`
:php:namespace:`LibraryName`
:php:func:`namespaced_function()`
Expand Down Expand Up @@ -416,7 +416,7 @@ Nested namespaces
Test Case - Test subpackage links
---------------------------------
:php:ns:`LibraryName\\SubPackage`
:php:namespace:`LibraryName\\SubPackage`
:php:ns:`\\LibraryName\\SubPackage`
Expand Down

0 comments on commit 4718cb2

Please sign in to comment.