Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using hoverxref with php domain ? #305

Open
nmatton opened this issue Sep 4, 2024 · 3 comments
Open

using hoverxref with php domain ? #305

nmatton opened this issue Sep 4, 2024 · 3 comments
Labels
Feature New feature

Comments

@nmatton
Copy link

nmatton commented Sep 4, 2024

I'm not completely familliar with the RTD architecture and domain principles, but I struggle to add crossref to a PHP class (or watherver) definition.

In short, when using the "default" cross-ref system, all works using

:php:class:\`FOO\\Helpers\\QueryBuilder\\QueryBuilder\`

However, I cannot find the equivalent using hoverxref

Here is my conf.py

extensions = [
    "myst_parser",
    "sphinx.ext.doctest",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.intersphinx",
    "sphinx.ext.autosectionlabel",
    'hoverxref.extension',
    'sphinx_rtd_theme',
    'sphinxcontrib.phpdomain',
    'sphinx_js']
autosectionlabel_prefix_document = True
hoverxref_domains = ['php']

And the file where the class is defined

QueryBuilder
============

.. php:namespace:: FOO\Helpers\QueryBuilder


.. php:class:: QueryBuilder


Can you give me some hint to solve the issue ? Thanks

Future work will be to cross ref some methods of the class and so on...

Thanks !

@humitos humitos added the Feature New feature label Sep 4, 2024
@humitos
Copy link
Member

humitos commented Sep 4, 2024

PHP Sphinx domain is not currently supported.

I think it could be added by doing something similar to what we are doing with the Python domain:

  • Declare the class for PHP domain:
    class HoverXRefPythonDomainMixin(HoverXRefBaseDomain):
    def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
    refnode = super().resolve_xref(env, fromdocname, builder, typ, target, node, contnode)
    if refnode is None:
    return refnode
    if self._is_ignored_ref(env, target):
    return refnode
    self._inject_hoverxref_data(env, refnode, typ)
    return refnode
  • Override the default class:
    if 'py' in app.config.hoverxref_domains:
    domain = types.new_class(
    'HoverXRefPythonDomain',
    (
    HoverXRefPythonDomainMixin,
    app.registry.domains.get('py'),
    ),
    {}
    )
    app.add_domain(domain, override=True)

Note that I'm not currently working on this extension to add new features since we replacing it with a more generic feature built-in into the Read the Docs platform.

@nmatton
Copy link
Author

nmatton commented Sep 5, 2024

Thanks for your answer.
I make it working on a local version (I have the tooltip openned with the "Loading...") but nothing when pushed to RTD.

What I did is

  • remove sphinx-hoverxref==1.4.0 from requirements.txt
  • update the extension.py as suggested (basically duplicating the lines 124-133 by replacing "py" by "php" + renaming "extension.py" to "hoverxref.py" and fixing (absolute) import issue
  • in conf.py: adding the line import os, sys; sys.path.insert(0,os.path.abspath('./hoverxref')) and replacing 'hoverxref.extension', by 'hoverxref', in extensions

However, the build in RTD does not show any error but it acts just like hoverxref was unexistent ...

I also have those lines in the build

Using default style (tooltip) for unknown typ (hoverxref). Define it in hoverxref_role_types.
Using default style (tooltip) for unknown typ (meth). Define it in hoverxref_role_types.
Using default style (tooltip) for unknown typ (hoverxref). Define it in hoverxref_role_types

which makes me think that hoverxref is present (I'm ok with the default, reason why I didn't define them in hoverxref_role_types. I have the same log warning in the local build)

Any idea ?

RTD build : https://app.readthedocs.org/projects/tisaac-boilerplate/builds/25533610/

Thanks !

@humitos
Copy link
Member

humitos commented Sep 9, 2024

I make it working on a local version (I have the tooltip openned with the "Loading...") but nothing when pushed to RTD.

Yeah, the extension doesn't work locally.

You should confirm that on Read the Docs you are executing your modified version of hoverxref. I guess you are not, because it should show at least the same "Loading..." message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature
Projects
None yet
Development

No branches or pull requests

2 participants