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

Snippet in same file to share docs #10820

Open
zhangzq opened this issue Apr 24, 2024 · 4 comments
Open

Snippet in same file to share docs #10820

zhangzq opened this issue Apr 24, 2024 · 4 comments
Labels
bug fixed but not released Bug is fixed in github, but still needs to make its way to an official release Fortran Python

Comments

@zhangzq
Copy link

zhangzq commented Apr 24, 2024

Hi, I need to share docs between functions and params.

As I know, writing the snippet in seperator example file and using @snippetdoc to include the file and snippet will works. But it will be more clear if I can write the snippet in the same file . In most case, I only use the snippet in same file.

Below is a short example. Currently it not works.

# example.py

## @snippet common_param_a
# @param a This is a common parameter that appears in many functions.
## @endsnippet common_param_a

## @brief This is a function.
# @snippetdoc common_param_a
# @param b This is another parameter.
def function1(a, b):
    pass

## @brief This is another function.
# @snippetdoc common_param_a
# @param c This is a different parameter.
def function2(a, c):
    pass
@zhangzq zhangzq changed the title snippet in same file to share docs [feature reqeust] snippet in same file to share docs Apr 24, 2024
@albert-github
Copy link
Collaborator

You wrote:

As I know, writing the snippet in separate example file and using @snippetdoc to include the file and snippet will works. But it will be more clear if I can write the snippet in the same file . In most case, I only use the snippet in same file.

Doxygen can have the code snippets in the same file and address these in the same way as it would do with do with snippets in a separate file, so can you show what you did:

  • Can you please attach a, small, self contained example (source+configuration file in a, compressed, tar or zip file!) that allows us to reproduce the problem? Please don't add external links as they might not be persistent (also references to GitHub repositories are considered non persistent).
  • Please also specify the full doxygen version used (doxygen -v).

Furthermore in your snippet you use the commands \snippet and \endsnippet:

  • \snippet is a doxygen command to include a code snippet, not to define a snippet
  • \endsnippet where is this command defined?
  • I don't see any snippet placeholder [...] in your code

I would have expected that the following would work:

## \file

# [common_param_a]
# @param a This is a common parameter that appears in many functions.
# [common_param_a]

## @brief This is a function.
#
# @snippetdoc example.py common_param_a
# @param b This is another parameter.
def function1(a, b):
    pass

## @brief This is another function.
#
# @snippetdoc example.py common_param_a
# @param c This is a different parameter.
def function2(a, c):
    pass

though this gives (in the current master version (1.11.0 (78422d3)):

example.py:4: warning: '\param' command is not allowed in section title, ending section title.
example.py:4: warning: '\param' command is not allowed in section title, ending section title.

and in the 1.10.0 version:

example.py:9: warning: The following parameter of example.function1(a, b) is not documented:
  parameter 'a'
example.py:16: warning: The following parameter of example.function2(a, c) is not documented:
  parameter 'a'

(Normally one would not use example.py in this case but the placeholder this but this didn't work in 1.10.0 but has been corrected in the mean time).

A workaround is currently:

## \file

""" [common_param_a]
    @param a This is a common parameter that appears in many functions.
    [common_param_a]"""

## @brief This is a function.
# @snippetdoc example.py common_param_a
# @param b This is another parameter.
def function1(a, b):
    pass

## @brief This is another function.
# @snippetdoc example.py common_param_a
# @param c This is a different parameter.
def function2(a, c):
    pass

@zhangzq
Copy link
Author

zhangzq commented Apr 25, 2024

you example works (previously I didn't know this), Thanks!

""" [common_param_a]
    @param a This is a common parameter that appears in many functions.
    [common_param_a]"""

## @brief This is a function.
# @snippetdoc this common_param_a
# @param b This is another parameter.
def function1(a, b):
    pass

@albert-github albert-github changed the title [feature reqeust] snippet in same file to share docs Snippet in same file to share docs Apr 25, 2024
albert-github added a commit to albert-github/doxygen that referenced this issue Apr 25, 2024
When having e.g.:
```
## \file

# [common_param_a]
#  @param a This is a common parameter that appears in many functions.
# [common_param_a]

## @brief This is a function.
#
# @snippetdoc example.py common_param_a
# @param b This is another parameter.
def function1(a, b):
    pass
```
or analogous in Fortran:
```
!> \file

! [ftn_common_param_a]
!  @param a This is a common parameter that appears in many functions.
! [ftn_common_param_a]

!> @brief This is a function.
!>
!> @snippetdoc this ftn_common_param_a
!> @param b This is another parameter.
subroutine ftn_function1(a, b)
    INTEGER a
    INTEGER b
end subroutine
```
we get warnings like:
```
example.py:4: warning: '\param' command is not allowed in section title, ending section title.
```
and in Fortran the `!` appears in the output

Whilst in C++ the analogous example:
```
/// \file

/** @brief This is a function.
 *  @snippet{doc} this cpp2_common_param_a
 *  @param b This is another parameter. */
void cpp2_function1(int a, int b){}

/*  [cpp2_common_param_a]
 *  @param a This is a common parameter that appears in many functions.
 *  [cpp2_common_param_a]
*/
```
works OK, due to the rule
```
<DocBlock>"\\ilinebr "{B}*"*"/[^/]      {
                                          QCString indent;
                                          indent.fill(' ',computeIndent(yytext+8,yyextra->column));
                                          yyextra->docBlock << "\\ilinebr " << indent;
                                        }
```
added analogous rules for python and Fortran.
@albert-github
Copy link
Collaborator

albert-github commented Apr 25, 2024

I've just pushed a proposed patch, pull request #10826

doxygen added a commit that referenced this issue Apr 28, 2024
@albert-github albert-github added the fixed but not released Bug is fixed in github, but still needs to make its way to an official release label Apr 28, 2024
@albert-github
Copy link
Collaborator

Code has been integrated in master on GitHub (please don't close the issue as this will be done at the moment of an official release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fixed but not released Bug is fixed in github, but still needs to make its way to an official release Fortran Python
Projects
None yet
Development

No branches or pull requests

2 participants