-
Notifications
You must be signed in to change notification settings - Fork 32
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
multilined cpp function signatures split between param name and datatype #14
Comments
The parameter wrapping is implemented here:
It looks like there will indeed need to be some tweaking of the C++ api formatting, in several different ways. Arguably the wrapping (for all languages) should be done using a code formatter rather than CSS like I have done, since you may need several levels of nesting for complicated template parameter lists, etc., but that might be a bit tricky. It looks like the |
Arguably the bug here is in the sphinx cpp domain itself --- the As far as adding icons to the secondary TOC for C++ "objects", I think that is independent of this issue, and could be done by adding some entries here:
|
At first glance, I kinda figured this issue wasn't exclusive to this theme. But, I'm glad I asked here first before taking this upstream. I still have to fully understand it all before taking any action whatsoever. Thanks again for the invaluable leads. |
While the structure of the |
Yeah I couldn't (readily) find a theme that separates the signature into multiple lines. Everything I've seen so far just shows the signature in 1 line (length be damned). |
I was able to solve this in CSS, but it is ugly as hell. I'll keep learning docutils (whose docs are ironically terrible), but for now I think I'll just add custom CSS to my projects until a more robust solution can be realized. .md-typeset dl.api-field>dt.sig-wrap .sig-param + .sig-param::before,
.md-typeset dl.objdesc>dt.sig-wrap .sig-param + .sig-param::before,
.md-typeset dl.api-field>dt.sig-wrap .n.sig-param + .kt::before,
.md-typeset dl.objdesc>dt.sig-wrap .n.sig-param + .kt::before,
.md-typeset dl.api-field>dt.sig-wrap .n.sig-param + .n:not(.sig-param)::before,
.md-typeset dl.objdesc>dt.sig-wrap .n.sig-param + .n:not(.sig-param)::before {
content: "\a ";
white-space: break-spaces;
} This still doesn't handle template parameters and the first arg to long function signatures... The later wouldn't be hard, but template descriptions is bit more complex since the entire signature is parsed from 1 long line - implying that we'd have to parse more than 1 set of brackets and determine if template/function/both parameters needs multiple lines. |
I've started expanding on the CSS solution currently implemented. I also went through and made sure that syntax highlighting is triggered properly (while still maintaining the I did look into patching the sphinx domains, but they are wildly different in construction. Also, I think the CSS approach can cover other added domains (not builtin to sphinx). |
I have actually been working heavily on generating C++ API documentation for TensorStore, and in the process have accumulated a large number of fixes to make the C++ domain work better for this theme (and work better in general). (Unfortunately they aren't really polished yet, as they are still a work in progress.) Initially I attempted to implement some wrapping rules for template parameters, function parameters, etc. However, C++ syntax is quite complicated, and at least for my use cases many different parts of the declarations might require wrapping, so I kept having to add additional wrapping rules. Therefore I abandoned that approach and instead implemented a sphinx extension that uses clang-format to format the C++ signatures. Using an existing formatter is probably also the way to go for Python and other languages. The advantage of clang-format is that it already has quite elaborate wrapping rules and provides a lot of customization via the style options. There is the PyPI clang-format package so there is no need for users to install it separately. Here is the code: https://gist.github.com/jbms/90e88d2c7a539b73614005bca02531bc The basic challenges are:
The same code could also be adapted to support other formatters/other languages pretty easily. |
ok! I'll separate the signature changes from the the other changes in the branch I'm working on. I have some experience with clang-format (& clang-tidy).
app.add_config_value(name='cpp_signature_clang_format_style', default='', rebuild='env') It would be clearer to users that the default style used in clang-format is the LLVM style. Users could change this to |
clang-format has quite a lot of options (https://clang.llvm.org/docs/ClangFormatStyleOptions.html) --- but I suppose there can always be more. I would suggest depending on the PyPI package rather than relying on a system-installed binary --- that way the version is consistent. The PyPI package has version 13.0.1. Unfortunately it does not have a later version though maybe they could be prodded into making one. I intended that users would indeed specify a custom style using that option. I think in many cases you may want a different style in the documentation from what is used in the source code. In particular for this theme the ColumnLimit should be set to 70. But yeah, perhaps |
Is is ok if I just augment my revised CSS solution with Could we use clang-format extension for any language that clang-format supports? Or is it designed only for C++? |
If you think your CSS solution is preferable to using an existing formatter in some cases then it seems reasonable for us to have that as well, for users that don't want to rely on an external formatter. It just seemed like to handle all of the cases you would end up having to basically implement a complete formatter, which is not something I wanted to do --- better to reuse the existing work. I think it doesn't necessarily need to explicitly exclude cpp --- we can probably arrange that a different way, e.g. via the The clang-format approach definitely could be used for any language supported by clang-format --- and in fact there is very little specific to clang-format --- it could be made more generic to work with basically any formatter for any language. |
I'm totally behind this idea. I'm just looking to fool-proof the CSS.
Yeah, that's what I meant. Unless I misunderstanding that comment. .sig-wrap:not(.cpp) {
// ...
} |
I think we can just arrange that |
Well It definitely works for C++ function args (doesn't account for template args). Ok, I'll not exclude |
Personally I don't really care for that syntax at all; it isn't real Python syntax, which means it can't be parsed into an AST properly, and therefore can't be properly cross-linked. Python syntax already provides a way to indicate optional arguments, so I don't see the point of that alternate syntax. |
I totally agree. Should I remove it? The docs that are referenced as the original RST source no longer uses the optional syntax. |
Yeah let's remove it. |
I'm getting ready to start exporting docygen XML to sphinx-immaterial (via
breathe
ext), and I noticed that function signatures that are wrapped to multiple lines are confusingly split between the parameter's datatype and name. Observe a test I made without doxygen/breathe (using standard sphinx cpp domain directives):I'm suspecting the fix should be placed in apidoc_formatting.py of this theme, but I still need to research more about how it detects the directive's domain.
The text was updated successfully, but these errors were encountered: