markstory / sphinxcontrib-phpdomain

A PHP domain for sphinx. Allows you to annotate PHP objects in your sphinx docs.
Other
19 stars 15 forks source link

namespaces with :noindex: are still indexed #27

Closed MarcelloPerathoner closed 4 years ago

MarcelloPerathoner commented 4 years ago

:noindex: on namespaces does not do what it is supposed to do:

.. php:namespace::x\y\z

.. php:namespace::x\y\z
   :noindex:

WARNING: :1: (SEVERE/4) Duplicate ID: "namespace-x\y\z".

markstory commented 4 years ago

For other domains does noindex prevent duplicate ids? My understanding was that noindex flags omitted the object from the generated index.

MarcelloPerathoner commented 4 years ago

If the php:namespace directive unconditionally adds an id then you will not be able to declare the same php:namespace in two different files. A quick look at the sphinx code shows that it never adds an id if noindex is set, but more safeguards against dup ids are needed:

in sphinx/directives/__init__.py

                if not noindex:
                    # only add target and index entry if this is the first
                    # description of the object with this name in this desc block
                    self.add_target_and_index(name, sig, signode)

in sphix/domains.c.py

    def add_target_and_index(self, name: str, sig: str, signode: desc_signature) -> None:
        # for C API items we add a prefix since names are usually not qualified
        # by a module name and so easily clash with e.g. section titles
        targetname = 'c.' + name
        if targetname not in self.state.document.ids:
            signode['names'].append(targetname)
            signode['ids'].append(targetname)
            signode['first'] = (not self.names)
            self.state.document.note_explicit_target(signode)
            ...
markstory commented 4 years ago

I took a look at how the python and ruby domains approach this problem and both of them provide a currentmodule directive which lets you document objects in a module, but not have links point to that location. I'll implement the same directive in this package for consistency with the rest of sphinx domains.