Open 2bndy5 opened 2 years ago
The lack of line numbers is due to https://github.com/sphinx-doc/sphinx/pull/10249
With line numbers the user would at least have an easy route to figure out which signature the warning relates to.
To me it seems like the warning is kind of useful in this case, though --- wouldn't it be better to include the parameter names, so that they can be cross-linked? And also then the user would more easily know which parameter is being described by the @param
comments.
In any case, sphinx does have the suppress_warnings
option:
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-suppress_warnings
I think we would need to do something to give this warning a recognizable warning type so that it could be targeted by that option.
We could then provide an example in the documentation of how to suppress this warning.
wouldn't it be better to include the parameter names, so that they can be cross-linked?
I'm not keen on forcing a feature on users that would break builds using the -W
option. I was hoping we could provide a cross_link_param_descriptions
option to allow disabling the feature for a more vanilla theme feel (especially for those trying to switch to this theme from another more basic sphinx theme).
I raised this issue specifically for the C++ domain because it could be considered a code style convention to omit param names in the function declarations. This example is taken from a breathe test that tells Doxygen not to resolve the param names when omitted from the declaration. So, it could be considered desirable (to omit param names) per project convention.
I didn't know about the suppress_warnings
option. But, I'm hesitant to rely on it because the docs you linked to noted:
Now, this option should be considered experimental.
Although its documented changes indicate that it has been around for a while, it also shows the heavily active development for it (but mostly just to add more warning types).
Adding an option to entirely disable cross linking of parameters seems reasonable, if that is the behavior you want. I thought you wanted to just avoid the warnings in case they can't be cross-linked. Perhaps it would be best as an object_description_option
so that it can be controlled per-domain and per object type.
Adding an option to entirely disable cross linking of parameters seems reasonable, if that is the behavior you want
Yes. This theme would be more flexible if it can provide an experience similar to any other sphinx theme.
Perhaps it would be best as an
object_description_option
so that it can be controlled per-domain and per object type.
My thoughts exactly. But, I'm having trouble imagining the practicality of such an option in domains other than cpp
.
The lack of line numbers is due to https://github.com/sphinx-doc/sphinx/pull/10249
My problem with the warning isn't the lack of line numbers; that wouldn't actually help in the instance of using breathe. My problem is the empty list of parameters that it is looking in. It would be easier to read the warning if I knew what function it is talking about (thus the hack I posted in the OP).
Including the signatures in the warning makes sense --- the desc_signature nodes can be obtained from obj_content.parent.children[:-1]
but then there is the issue of handling "api-include-path" so it would be better, I think, to just pass the list of signodes
into that function.
Implementing this in the C++ domain was easy, but it looks like the python domain has 2 instances where parameters are cross-linked to descriptions:
py:parameter
s)py:function
usage namely the optional syntax in our docs: https://github.com/jbms/sphinx-immaterial/blob/d874316382d3413ab4b78c2563754b4b225cc525/docs/additional_samples.rst#L225EDIT: It looks like case 2 calls case 1. So, I making either py:function
or py:parameter
be controlled with the new cross_link_parameter_description
option. This should follow suite with how the C/C++ domain works (in regard to the new option), although I think there are other things like c:*Param
that are also effected (good thing we have the regex support).
I was able to get an adequate signature in the warning by using obj_content.parent.children[0].astext()
See also https://github.com/jbms/sphinx-immaterial/pull/114#discussion_r911622440 for a fully diagnosed proposal.
I'm trying to go forward with the proposal from https://github.com/jbms/sphinx-immaterial/pull/114#discussion_r911622440 which said:
Perhaps there should be some finer-grained options rather than just this one option to disable the generation of
parameter
objects entirely. E.g.:object_description_options:
generate_parameter_objects: bool = True
--- enables generation of parameter objects from:param xx:
fields in the object description; these parameter objects can be cross-referenced (with synopsis shown depending ongenerate_synopsis
), appear in search results, and can be shown in the TOC (depending oninclude_in_toc
).cross_link_signature_parameters: bool = True
--- cross-links parameters defined in signatures to the parameter objects defined bygenerate_parameter_objects
. Has no effect ifgenerate_parameter_objects
isFalse
.nitpick_parameter_names: bool = True
--- emits a warning if a parameter documented with:param:
can't be matched to a parameter defined by a signature. Has no effect if eithercross_link_signature_parameters
orgenerate_parameter_objects
isFalse
.
The following are my initial impressions that correspond the the above proposed list of new obj_desc_opts. Most of the problems I'm finding seem like a "chicken before the egg" conundrum.
get_objects()
nitpick_parameter_warnings
can only be fetched if the precise parameter type is known. Since the warning is spawned from not finding the parameter in the signature (& precise parameter type is determined after the finding the parameter in the signature), there's no way to fetch the obj_desc_opt about the precise type of parameter.Maybe I'm missing somethings, but points 1 & 3 may require a significant re-work of the code base. Like I said, these are just my first impressions (since letting this issue get stale after #114). TBH, I still think a single option to allow/disallow the cross-linking of parameters in signatures would be the simplest solution for this issue.
I think the chicken and egg issue can be solved by making nitpick_parameter_names and generate_parameter_objects options of the parent object (e.g. cpp:func) rather than the parameter object itself.
Well the parent tactic worked for nitpick_parameter_names,
but now I'm having trouble differentiating between the actual code needed to cross-link parameter fields and the creation of parameter objects from :param x:
fields. Locally, I'm just treating the cross_link_signature_parameters
the same as generate_parameter_objects
.
Instead of altering the docs, I'm writing unit tests to ensure the options are doing what they're supposed to.
Its rather common to document a header that has no parameter names (only datatypes) when the parameter names only exist in the implementation file.
However, this theme expects the declaration signature to have the parameter names.
Furthermore, the warning message for this situation isn't very helpful:
Ideas
resulting in a warning that reads:
I'm sure there's a cleaner way of doing this.