fortran-lang / fortls

fortls - Fortran Language Server
https://fortls.fortran-lang.org/
MIT License
258 stars 41 forks source link

Doxygen style comments are sometimes picked up in the wrong place #237

Open plevold opened 2 years ago

plevold commented 2 years ago

Describe the bug Due to the way fortls parses Doxygen style comments they could appear in unexpected places if a developer is not careful about using !> comments.

To Reproduce In the following example:

subroutine sub_before
    integer :: i

    !> Trying to add a docstring to an expression
    i = 1
end subroutine

subroutine sub_no_doc
end subroutine

The comment !> Trying to add a docstring to an expression is added as a docstring to sub_no_doc.

Expected behavior When building the AST, pendic_doc should probably be cleared when something other than subroutine / function / type / module appears.

See also https://github.com/fortran-lang/fortls/issues/212#issuecomment-1299691619

gnikit commented 2 years ago

Cheers @plevold, so this should be attached to the integer :: i AST node. If placed in the same line as integer :: i then it attaches correctly. I suspect what I need to do is ignore new lines and attached to the previous AST node. Not sure if that will break the existing parser.

folk85 commented 1 year ago

I think that it's not bug. If I change the !> to !< it would work properly. image image