julia-vscode / DocumentFormat.jl

Auto-formatter for Julia
Other
62 stars 18 forks source link

Aligning docstrings and comments #22

Closed domluna closed 2 years ago

domluna commented 6 years ago

@ZacLN

Currently the formatter doesn't properly align docstrings and comments.

begin

"""
doc for `foo`
"""
function foo()
    return 10
end

end

formats to:

begin

    """
doc for `foo`
"""
function foo()
    return 10
end

end

I have a POC which treats each line in the doc as a LITERAL instead of the entire doc as one LITERAL and this works, also needs come changes to get_lines. We could do something similar for comments but it's trickier since at the moment CSTParser ignores comments.

We could add something like

abstract type Comment <: Head end
abstract type MultiLineComment <: Head end

to spec.jl and then store the comments as LITERALS, MultiLineComment would be similar to how docstrings work.

I have some WIP on these things but would like to hear your thoughts before I proceed further.

ZacLN commented 6 years ago

I don't think modifications to CSTParser are the correct route for this, having a quick glance I think we should be able to hand this through modifying get_lines. I think handling comments explicitly in CSTParser would add too many complications to the token look ahead mechanism