sphinx-contrib / matlabdomain

A Sphinx extension for documenting Matlab code
http://sphinxcontrib-matlabdomain.readthedocs.io/
Other
70 stars 46 forks source link

can't link function short name if it matches module name #243

Open rdzman opened 8 months ago

rdzman commented 8 months ago

Given a module named foo and a function within that module, also named foo, with matlab_short_links = True, it is not possible to create a working link to the function. Both of the following result in a properly formatted, but not hyperlinked, name.

:func:`foo`
:func:`foo.foo`

With matlab_short_links = False both work just fine.

Note: The behavior of the first one depends on whether you have an .. automodule:: foo anywhere or not. If so, it links to the foo module, if not, to the foo.foo function.

I believe it should behave exactly the same way with matlab_short_links = True, right?

There is an additional issue with matlab_auto_link = "all" that prevents it from recognizing foo as a function in this context and wrapping it with the :func: role. (I think I have a fix for this part.)

Finally, while I haven't tested it, I suspect that a class with the same name as the module probably has the same problem.

joeced commented 8 months ago

Thanks for the report. I'll try to look at it soon

joeced commented 3 months ago

Short update. I finally had time to work on the project this weekend. Today I started looking into why the links don't work as we expect. The culprit is https://github.com/sphinx-contrib/matlabdomain/blob/b081e7c3473097ff41f4d9dc1f666cb6bdfebd3e/sphinxcontrib/matlab.py#L718 which I have not touched at all. It looks like it was copied verbatim from the Python domain. I'll modify it to match how we want to find objects to link to :)

joeced commented 3 months ago

I started working on this in a branch: https://github.com/sphinx-contrib/matlabdomain/tree/try-fix-auto-linking.

@rdzman do you have time to test this? I'll be away from a computer for 3 weeks in a few days, so it'll take a while before its out as a release.

rdzman commented 3 months ago

@joeced, is it possible the issue at #246 is getting conflated with this one? From what I understand, the presenting issue here was "fixed", probably incorrectly by #245.

Unfortunately, I have very limited time for testing at the moment, but a quick try on some of my projects with the try-fix-auto-linking branch results in lots of new warnings, such as the following ...

/Users/ray/dev/projects/mp-opt-model/docs/sphinx/docstring of mp_opt_model.have_feature_fsolve:1: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'fsolve': have_feature_fsolve, nleqs_fsolve
/Users/ray/dev/projects/mp-opt-model/docs/sphinx/docstring of mp_opt_model.have_feature_fsolve:3: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'fsolve': have_feature_fsolve, nleqs_fsolve

or

/Users/ray/dev/projects/matpower/docs/sphinx/docstring of matpower.have_feature_most:6: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'most': most.most, mpoption_info_most, t_case30_most, t_case3_most, test_most, have_feature_most

I haven't noticed any changes in links created relative to the above warnings.

However, I am seeing cases where there are functions that were not linked (I think due to #246), that are now being linked, but to the wrong target. E.g. :func:``mpoption`` being linked to a function named t_mpoption.