Skip to content

[meta issue] preserving syntax trivia and comments #306

@smoothdeveloper

Description

@smoothdeveloper

I noticed that the pretty printer basically drops all comments, and that upstream, comments are parsed but basically dropped.

In F# compiler, there has been some ground work done to better preserve syntax trivia, such as precise placement of keywords, and also preserving the comments.

One thing which is done there, is that all the comments are tucked in a single list for the implementation (or signature) file:

https://github.com/dotnet/fsharp/blob/70171b7ebd461c10345861558c8afddc84e8ef29/src/Compiler/SyntaxTree/SyntaxTrivia.fs#L31-L35

This allows pretty printer tool (for F#, the main one is called Fantomas) to reintegrate the comments while also not making the AST more complex due to handling of comments.

I think it also keeps the parsing simple, where we could start building this comment list and attach it to a top level element in the AST.

If I can get a bit of guidance about which part of the AST we'd like to aggregate the comments, and how to do that in the parser implementation, I may give it a shot.

related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions